date.getDay
date.getDay
getDay()
方法根据本地时间返回指定日期的星期值,其中0代表星期日。查看指定日期在这个月的哪一天,请用getDate()
。
语法
dateObj.getDay()
返回值
根据当地时间,给定日期所对应的整数编号为: 周日为0,周一为1,周二为2,以此类推。
例子
使用 getDay()
下面的第二个语句根据Date
对象Xmas95
的值,将值1分配给变量weekday
。 December 25, 1995 是 星期一。
var Xmas95 = new Date('December 25, 1995 23:15:30'
var weekday = Xmas95.getDay(
console.log(weekday // 1
规格
Specification | Status | Comment |
---|---|---|
ECMAScript Latest Draft (ECMA-262)The definition of 'Date.prototype.getDay' in that specification. | Living Standard | |
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Date.prototype.getDay' in that specification. | Standard | |
ECMAScript 5.1 (ECMA-262)The definition of 'Date.prototype.getDay' in that specification. | Standard | |
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.0. |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |