创建一个 JavaScript Date
实例,该实例呈现时间中的某个时刻。Date
对象则基于 Unix Time Stamp,即自1970年1月1日(UTC)起经过的毫秒数。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
实例化Date对象
创建一个新Date
对象的唯一方法是通过new
操作符:
let now = new Date();
只能将 Date
作为构造函数调用,才能实例化(instantiate) Date
对象:若将它作为常规函数调用(即不加 new
操作符),则将会返回一个字符串,而非 Date
对象。另外,不像其他的 JavaScript 对象类型,Date
对象没有字面量语法(literal syntax)。
语法
new Date(); new Date(value); new Date(dateString); new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);
参数
注意 参数monthIndex
是从“0”开始计算的,这就意味着一月份为“0”,十二月份为“11”。
注意:当Date作为构造函数调用并传入多个参数时,如果数值大于合理范围时(如月份为 13 或者分钟数为 70),相邻的数值会被调整。比如 new Date(2013, 13, 1)等于new Date(2014, 1, 1),它们都表示日期2014-02-01(注意月份是从0开始的)。其他数值也是类似,new Date(2013, 2, 1, 0, 70)等于new Date(2013, 2, 1, 1, 10),都表示同一个时间:2013-03-01T01:10:00
。
注意:当Date作为构造函数调用并传入多个参数时,所定义参数代表的是当地时间。如果需要使用世界协调时 UTC,使用 new Date(
和相同参数。Date.UTC(...)
)
Date()
构造函数有四种基本形式
没有参数
如果没有提供参数,那么新创建的Date对象表示实例化时刻的日期和时间。
Unix时间戳
-
value
- 一个 Unix 时间戳( Unix Time Stamp),它是一个整数值,表示自1970年1月1日00:00:00 UTC(the Unix epoch)以来的毫秒数,忽略了闰秒。请注意大多数 Unix 时间戳功能仅精确到最接近的秒。
-
时间戳字符串
-
dateString
-
表示日期的字符串值。该字符串应该能被
Date.parse()
正确方法识别(即符合 IETF-compliant RFC 2822 timestamps 或 version of ISO8601)。注意: 由于浏览器之间的差异与不一致性,强烈不推荐使用
Date
构造函数来解析日期字符串 (或使用与其等价的Date.parse
)。对 RFC 2822 格式的日期仅有约定俗称的支持。 对 ISO 8601 格式的支持中,仅有日期的串 (例如 "1970-01-01") 会被处理为 UTC 而不是本地时间,与其他格式的串的处理不同。
分别提供日期与时间的每一个成员
当至少提供了年份与月份时,这一形式的 Date()
返回的 Date
对象中的每一个成员都来自下列参数。没有提供的成员将使用最小可能值(对日期为1
,其他为0
)。
-
year
- 表示年份的整数值。 0到99会被映射至1900年至1999年,其它值代表实际年份。参见 示例。
-
monthIndex
- 表示月份的整数值,从 0(1月)到 11(12月)。
-
day
可选 - 表示一个月中的第几天的整数值,从1开始。默认值为1。
-
hours
可选 - 表示一天中的小时数的整数值 (24小时制)。默认值为0(午夜)。
-
minutes
可选 - 表示一个完整时间(如 01:10:00)中的分钟部分的整数值。默认值为0。
-
seconds
可选 - 表示一个完整时间(如 01:10:00)中的秒部分的整数值。默认值为0。
-
milliseconds
可选 - 表示一个完整时间的毫秒部分的整数值。默认值为0。
简介
- 如果没有输入任何参数,则Date的构造器会依据系统设置的当前时间来创建一个Date对象。
- 如果提供了至少两个参数,其余的参数均会默认设置为 1(如果没有指定 day 参数)或者 0(如果没有指定 day 以外的参数)。
- JavaScript的时间由世界标准时间(UTC)1970年1月1日开始,用毫秒计时,一天由 86,400,000 毫秒组成。
Date
对象的范围是 -100,000,000 天至 100,000,000 天(等效的毫秒值)。 Date
对象为跨平台提供了统一的行为。时间属性可以在不同的系统中表示相同的时刻,而如果使用了本地时间对象,则反映当地的时间。Date
对象支持多个处理 UTC 时间的方法,也相应地提供了应对当地时间的方法。UTC,也就是我们所说的格林威治时间,指的是time中的世界时间标准。而当地时间则是指执行JavaScript的客户端电脑所设置的时间。- 以一个函数的形式来调用
Date
对象(即不使用new
操作符)会返回一个代表当前日期和时间的字符串。
属性
-
Date.prototype
-
允许为
Date
对象添加属性。 -
Date.length
-
Date.length
的值是 7。这是该构造函数可接受的参数个数。
方法
-
Date.now()
- 返回自 1970-1-1 00:00:00 UTC(世界标准时间)至今所经过的毫秒数。
-
Date.parse()
-
解析一个表示日期的字符串,并返回从 1970-1-1 00:00:00 所经过的毫秒数。
注意: 由于浏览器差异和不一致,强烈建议不要使用
Date.parse
解析字符串。 -
Date.UTC()
- 接受和构造函数最长形式的参数相同的参数(从2到7),并返回从 1970-01-01 00:00:00 UTC 开始所经过的毫秒数。
JavaScript Date
实例
所有的 Date
实例都继承自 Date.prototype
。修改 Date
构造函数的原型对象会影响到所有的 Date
实例。
Date.prototype 方法
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()
- 根据世界时返回特定日期对象一个月的第几天(1-31).
-
Date.prototype.getUTCDay()
- 根据世界时返回特定日期对象一个星期的第几天(0-6).
-
Date.prototype.getUTCFullYear()
- 根据世界时返回特定日期对象所在的年份(4位数).
-
Date.prototype.getUTCHours()
- 根据世界时返回特定日期对象当前的小时(0-23).
-
Date.prototype.getUTCMilliseconds()
- 根据世界时返回特定日期对象的毫秒数(0-999).
-
Date.prototype.getUTCMinutes()
- 根据世界时返回特定日期对象的分钟数(0-59).
-
Date.prototype.getUTCMonth()
- 根据世界时返回特定日期对象的月份(0-11).
-
Date.prototype.getUTCSeconds()
- 根据世界时返回特定日期对象的秒数(0-59).
-
Date.prototype.getYear()
-
根据特定日期返回年份 (通常 2-3 位数). 使用
getFullYear()
.
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()
方法。
例子
>例子:创建一个日期对象的几种方法
下例展示了用来创建一个日期对象的多种方法。
注意: 由于浏览器差异和不一致性,强烈建议不要使用Date
构造函数(和Date.parse
,它们是等效的)解析日期字符串。
var today = new Date(); var birthday = new Date('December 17, 1995 03:24:00'); var birthday = new Date('1995-12-17T03:24:00'); var birthday = new Date(1995, 11, 17); var birthday = new Date(1995, 11, 17, 3, 24, 0);
例子:将两位数年份映射为 1900 - 1999 年
为了创建和获取 0 到 99 之间的年份,应使用 Date.prototype.getFullYear()
方法。
var date = new Date(98, 1); // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT) // 已弃用的方法, 同样将 98 映射为 1998 date.setYear(98); // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT) date.setFullYear(98); // Sat Feb 01 0098 00:00:00 GMT+0000 (BST)
例子:计算经过的时间
下例展示了如何以毫秒精度计算两个日期对象的时间差:
由于不同日期、月份、年份长度的不同(日期长度不同来自夏令时的切换),使用大于秒、分钟、小时的单位表示经过的时间会遇到很多问题,在使用前需要经过详尽的调研。
// 使用 Date 对象 var start = Date.now(); // 调用一个消耗一定时间的方法: doSomethingForALongTime(); var end = Date.now(); var elapsed = end - start; // 以毫秒计的运行时长
// 使用内建的创建方法 var start = new Date(); // 调用一个消耗一定时间的方法: doSomethingForALongTime(); var end = new Date(); var elapsed = end.getTime() - start.getTime(); // 运行时间的毫秒值
// to test a function and get back its return function printElapsedTime (fTest) { var nStartTime = Date.now(), vReturn = fTest(), nEndTime = Date.now(); alert("Elapsed time: " + String(nEndTime - nStartTime) + " milliseconds"); return vReturn; } yourFunctionReturn = printElapsedTime(yourFunction);
注意:在支持 Web Performance API
的高精细度(high-resolution)时间功能的浏览器中,Performance.now()
提供的所经过的时间比 Date.now()
更加可靠、精确。
获取自 Unix 起始时间以来经过的秒数
var seconds = Math.floor(Date.now() / 1000);
注意此处需要返回一个整数 (仅做除法得到的不是整数),并且需要返回实际已经经过的秒数(所以这里使用了Math.round()
).
规范
规范版本 | 规范状态 | 注解 |
---|---|---|
ECMAScript Latest Draft (ECMA-262) Date |
Draft | |
ECMAScript 2015 (6th Edition, ECMA-262) Date |
Standard | |
ECMAScript 5.1 (ECMA-262) Date |
Standard | |
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.1. |
浏览器兼容性
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Date |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3
|
Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
UTC |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getDate |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getDay |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getFullYear |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getHours |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getMilliseconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getMinutes |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getMonth |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getSeconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getTime |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getTimezoneOffset |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCDate |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCDay |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCFullYear |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCHours |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCMilliseconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCMinutes |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCMonth |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getUTCSeconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
getYear
|
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
now |
Chrome Full support 5 | Edge Full support 12 | Firefox Full support 3 | IE Full support 9 | Opera Full support 10.5 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes |
parse |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
prototype |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1
|
IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4
|
Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setDate |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setFullYear |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setHours |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setMilliseconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setMinutes |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setMonth |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setSeconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setTime |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setUTCDate |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setUTCFullYear |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setUTCHours |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setUTCMilliseconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setUTCMinutes |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setUTCMonth |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setUTCSeconds |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
setYear
|
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toDateString |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toGMTString
|
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toISOString |
Chrome Full support 3 | Edge Full support 12 | Firefox Full support 1 | IE Full support 9 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toJSON |
Chrome Full support 3 | Edge Full support 12 | Firefox Full support 1 | IE Full support 8 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toLocaleDateString |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toLocaleFormat
|
Chrome No support No | Edge No support No | Firefox No support 1.5 — 58 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 4 — 58 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
toLocaleString |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toLocaleTimeString |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toSource
|
Chrome No support No | Edge No support No | Firefox Full support 1 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android Full support 4 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
toString |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toTimeString |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
toUTCString |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
valueOf |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
@@toPrimitive |
Chrome Full support 47 | Edge Full support 15 | Firefox Full support 44 | IE No support No | Opera Full support 34 | Safari ? | WebView Android Full support 47 | Chrome Android Full support 47 | Firefox Android Full support 44 | Opera Android Full support 34 | Safari iOS ? | Samsung Internet Android Full support 5.0 | nodejs Full support 6.0.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.
- See implementation notes.
- See implementation notes.