这篇翻译不完整。请帮忙从英语翻译这篇文章。
概述
Date.prototype
属性表示 Date
构造函数的原型。
Date.prototype 属性的属性特性: |
|
---|---|
writable | false |
enumerable | false |
configurable | true |
描述
Date
实例继承自Date.prototype
。 可以通过修改构造函数的原型对象来影响 Date 实例继承的属性和方法。
为了兼容千禧年计算(也即考虑到 2000 年),应该总是指定完整的年份,例如,使用 1998,而不是 98。为了方便以完整的格式指定年份, JavaScript 包含了相应的方法getFullYear()
,setFullYear()
, getUTCFullYear()
和setUTCFullYear()
。
属性
- Date.prototype.constructor
- 返回创建该实例的函数。默认情况下,是
Date
Date
构造函数。
方法
Getter
Date.prototype.getDate()
- 根据本地时间返回指定日期对象的月份中的第几天(1-31)。
Date.prototype.getDay()
- 根据本地时间返回指定日期对象的星期中的第几天(0-6)。
Date.prototype.getFullYear()
- 根据本地时间返回指定日期对象的年份(四位数年份时返回四位数字)。
Date.prototype.getHours()
- 根据本地时间返回指定日期对象的小时(0-23)。
Date.prototype.getMilliseconds()
- 根据本地时间返回指定日期对象的微秒(0-999)。
Date.prototype.getMinutes()
- 根据本地时间返回指定日期对象的分钟(0-59)。
Date.prototype.getMonth()
- 根据本地时间返回指定日期对象的月份(0-11)。
Date.prototype.getSeconds()
- 根据本地时间返回指定日期对象的秒数(0-59)。
Date.prototype.getTime()
- 返回从1970-1-1 00:00:00 UTC(协调世界时)到该日期经过的毫秒数,对于1970-1-1 00:00:00 UTC之前的时间返回负值。
Date.prototype.getTimezoneOffset()
- 返回当前时区的时区偏移。
Date.prototype.getUTCDate()
- Returns the day (date) of the month (1-31) in the specified date according to universal time.
Date.prototype.getUTCDay()
- Returns the day of the week (0-6) in the specified date according to universal time.
Date.prototype.getUTCFullYear()
- Returns the year (4 digits for 4-digit years) in the specified date according to universal time.
Date.prototype.getUTCHours()
- Returns the hours (0-23) in the specified date according to universal time.
Date.prototype.getUTCMilliseconds()
- Returns the milliseconds (0-999) in the specified date according to universal time.
Date.prototype.getUTCMinutes()
- Returns the minutes (0-59) in the specified date according to universal time.
Date.prototype.getUTCMonth()
- Returns the month (0-11) in the specified date according to universal time.
Date.prototype.getUTCSeconds()
- Returns the seconds (0-59) in the specified date according to universal time.
Date.prototype.getYear()
- Returns the year (usually 2-3 digits) in the specified date according to local time. Use
getFullYear()
instead.
Setter
Date.prototype.setDate()
- 根据本地时间为指定的日期对象设置月份中的第几天。
Date.prototype.setFullYear()
- 根据本地时间为指定日期对象设置完整年份(四位数年份是四个数字)。
Date.prototype.setHours()
- 根据本地时间为指定日期对象设置小时数。
Date.prototype.setMilliseconds()
- 根据本地时间为指定日期对象设置毫秒数。
Date.prototype.setMinutes()
- 根据本地时间为指定日期对象设置分钟数。
Date.prototype.setMonth()
- 根据本地时间为指定日期对象设置月份。
Date.prototype.setSeconds()
- 根据本地时间为指定日期对象设置秒数。
Date.prototype.setTime()
- 通过指定从 1970-1-1 00:00:00 UTC 开始经过的毫秒数来设置日期对象的时间,对于早于 1970-1-1 00:00:00 UTC的时间可使用负值。
Date.prototype.setUTCDate()
- 根据世界时设置 Date 对象中月份的一天 (1 ~ 31)。
Date.prototype.setUTCFullYear()
- 根据世界时设置 Date 对象中的年份(四位数字)。
Date.prototype.setUTCHours()
- 根据世界时设置 Date 对象中的小时 (0 ~ 23)。
Date.prototype.setUTCMilliseconds()
- 根据世界时设置 Date 对象中的毫秒 (0 ~ 999)。
Date.prototype.setUTCMinutes()
- 根据世界时设置 Date 对象中的分钟 (0 ~ 59)。
Date.prototype.setUTCMonth()
- 根据世界时设置 Date 对象中的月份 (0 ~ 11)。
Date.prototype.setUTCSeconds()
- 根据世界时设置 Date 对象中的秒钟 (0 ~ 59)。
Date.prototype.setYear()
- setYear() 方法用于设置年份。请使用
setFullYear()
方法代替。
Conversion getter
Date.prototype.toDateString()
- 以人类易读(human-readable)的形式返回该日期对象日期部分的字符串。
Date.prototype.toISOString()
- 把一个日期转换为符合 ISO 8601 扩展格式的字符串。
Date.prototype.toJSON()
- 使用
toISOString()
返回一个表示该日期的字符串。为了在JSON.stringify()
方法中使用。 Date.prototype.toGMTString()
- 返回一个基于 GMT (UT) 时区的字符串来表示该日期。请使用
toUTCString()
方法代替。 Date.prototype.toLocaleDateString()
- 返回一个表示该日期对象日期部分的字符串,该字符串格式与系统设置的地区关联(locality sensitive)。
Date.prototype.toLocaleFormat()
- 使用格式字符串将日期转换为字符串。
Date.prototype.toLocaleString()
- 返回一个表示该日期对象的字符串,该字符串与系统设置的地区关联(locality sensitive)。覆盖了
Object.prototype.toLocaleString()
方法。 Date.prototype.toLocaleTimeString()
- 返回一个表示该日期对象时间部分的字符串,该字符串格式与系统设置的地区关联(locality sensitive)。
Date.prototype.toSource()
- 返回一个与
Date
等价的原始字符串对象,你可以使用这个值去生成一个新的对象。重写了Object.prototype.toSource()
这个方法。 Date.prototype.toString()
- 返回一个表示该日期对象的字符串。覆盖了
Object.prototype.toString()
方法。 Date.prototype.toTimeString()
- 以人类易读格式返回日期对象时间部分的字符串。
Date.prototype.toUTCString()
- 把一个日期对象转换为一个以UTC时区计时的字符串。
Date.prototype.valueOf()
- 返回一个日期对象的原始值。覆盖了
Object.prototype.valueOf()
方法。
规范
规范版本 | 规范状态 | 注解 |
---|---|---|
ECMAScript 1st Edition. Implemented in JavaScript 1.1 | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262) Date.prototype |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) Date.prototype |
Standard |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |