JavaScript Date objects represent a single moment in time in a platform-independent format. Date objects contain a Number that represents milliseconds since 1 January 1970 UTC.

TC39 is working on Temporal , a new Date/Time API.
Read more about it on the Igalia blog and fill out the survey . It needs real-world feedback from web developers, but is not yet ready for production use!

描述

ECMAScript 纪元和时间戳

A JavaScript date is fundamentally specified as the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC. This date and time is the same as the UNIX epoch , which is the predominant base value for computer-recorded date and time values.

注意: It's important to keep in mind that while the time value at the heart of a Date object is UTC, the basic methods to fetch the date and time or its components all work in the local (i.e. host system) time zone and offset.

It should be noted that the maximum Date is not of the same value as the maximum safe integer ( Number.MAX_SAFE_INTEGER is 9,007,199,254,740,991). Instead, it is defined in ECMA-262 that a maximum of ±100,000,000 (one hundred million) days relative to January 1, 1970 UTC (that is, April 20, 271821 BCE ~ September 13, 275760 CE) can be represented by the standard Date object (equivalent to ±8,640,000,000,000,000 milliseconds).

日期格式和时区转换

There are a number of methods available to obtain a date in various formats, as well as to perform time zone conversions. Particularly useful are the functions that output the date and time in Coordinated Universal Time (UTC), the global standard time defined by the World Time Standard. (This time is historically known as Greenwich Mean Time , as UTC lies along the meridian that includes London—and nearby Greenwich—in the United Kingdom.) The user's device provides the local time.

In addition to methods to read and alter individual components of the local date and time (such as getDay() and setHours() ), there are also versions of the same methods that read and manipulate the date and time using UTC (such as getUTCDay() and setUTCHours() ).

构造函数

Date()
创建新的 Date 对象。

静态方法

Date.now()

Returns the numeric value corresponding to the current time—the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC, with leap seconds ignored.

Date.parse()
Parses a string representation of a date and returns the number of milliseconds since 1 January, 1970, 00:00:00 UTC, with leap seconds ignored.

注意: Parsing of strings with Date.parse is strongly discouraged due to browser differences and inconsistencies.

Date.UTC()

Accepts the same parameters as the longest form of the constructor (i.e. 2 to 7) and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC, with leap seconds ignored.

实例方法

Date.prototype.getDate()
Returns the day of the month ( 1 31 ) for the specified date according to local time.
Date.prototype.getDay()
Returns the day of the week ( 0 6 ) for the specified date according to local time.
Date.prototype.getFullYear()

Returns the year (4 digits for 4-digit years) of the specified date according to local time.

Date.prototype.getHours()
Returns the hour ( 0 23 ) in the specified date according to local time.
Date.prototype.getMilliseconds()
Returns the milliseconds ( 0 999 ) in the specified date according to local time.
Date.prototype.getMinutes()
Returns the minutes ( 0 59 ) in the specified date according to local time.
Date.prototype.getMonth()
Returns the month ( 0 11 ) in the specified date according to local time.
Date.prototype.getSeconds()
Returns the seconds ( 0 59 ) in the specified date according to local time.
Date.prototype.getTime()

Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC. (Negative values are returned for prior times.)

Date.prototype.getTimezoneOffset()

Returns the time-zone offset in minutes for the current locale.

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() 代替。
Date.prototype.setDate()

Sets the day of the month for a specified date according to local time.

Date.prototype.setFullYear()

Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to local time.

Date.prototype.setHours()

Sets the hours for a specified date according to local time.

Date.prototype.setMilliseconds()

Sets the milliseconds for a specified date according to local time.

Date.prototype.setMinutes()

Sets the minutes for a specified date according to local time.

Date.prototype.setMonth()

Sets the month for a specified date according to local time.

Date.prototype.setSeconds()

Sets the seconds for a specified date according to local time.

Date.prototype.setTime()
设置 Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC. Use negative numbers for times prior.
Date.prototype.setUTCDate()

Sets the day of the month for a specified date according to universal time.

Date.prototype.setUTCFullYear()

Sets the full year (e.g. 4 digits for 4-digit years) for a specified date according to universal time.

Date.prototype.setUTCHours()

Sets the hour for a specified date according to universal time.

Date.prototype.setUTCMilliseconds()

Sets the milliseconds for a specified date according to universal time.

Date.prototype.setUTCMinutes()

Sets the minutes for a specified date according to universal time.

Date.prototype.setUTCMonth()

Sets the month for a specified date according to universal time.

Date.prototype.setUTCSeconds()

Sets the seconds for a specified date according to universal time.

Date.prototype.setYear()
Sets the year (usually 2–3 digits) for a specified date according to local time. Use setFullYear() 代替。
Date.prototype.toDateString()
Returns the "date" portion of the Date as a human-readable string like 'Thu Apr 12 2018' .
Date.prototype.toISOString()

Converts a date to a string following the ISO 8601 Extended Format.

Date.prototype.toJSON()
Returns a string representing the Date 使用 toISOString() . Intended for use by JSON.stringify() .
Date.prototype.toGMTString()
Returns a string representing the Date based on the GMT (UTC) time zone. Use toUTCString() 代替。
Date.prototype.toLocaleDateString()

Returns a string with a locality sensitive representation of the date portion of this date based on system settings.

Date.prototype.toLocaleFormat()

Converts a date to a string, using a format string.

Date.prototype.toLocaleString()
Returns a string with a locality-sensitive representation of this date. Overrides the Object.prototype.toLocaleString() 方法。
Date.prototype.toLocaleTimeString()

Returns a string with a locality-sensitive representation of the time portion of this date, based on system settings.

Date.prototype.toString()
Returns a string representing the specified Date object. Overrides the Object.prototype.toString() 方法。
Date.prototype.toTimeString()
Returns the "time" portion of the Date as a human-readable string.
Date.prototype.toUTCString()

Converts a date to a string using the UTC timezone.

Date.prototype.valueOf()
Returns the primitive value of a Date object. Overrides the Object.prototype.valueOf() 方法。

范例

创建日期对象的几种方式

The following examples show several ways to create JavaScript dates:

注意: Parsing of date strings with the Date constructor (and Date.parse , they are equivalent) is strongly discouraged due to browser differences and inconsistencies.

let today = new Date()
let birthday = new Date('December 17, 1995 03:24:00')
let birthday = new Date('1995-12-17T03:24:00')
let birthday = new Date(1995, 11, 17)            // the month is 0-indexed
let birthday = new Date(1995, 11, 17, 3, 24, 0)
let birthday = new Date(628021800000)            // passing epoch timestamp
					

获取日期、月份和年份或时间

let [month, date, year]    = ( new Date() ).toLocaleDateString().split("/")
let [hour, minute, second] = ( new Date() ).toLocaleTimeString().slice(0,7).split(":")
					

2 位数年份映射到 1900 – 1999

In order to create and get dates between the years 0 and 99 the Date.prototype.setFullYear() and Date.prototype.getFullYear() methods should be used.

let date = new Date(98, 1)  // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT)
// Deprecated method; 98 maps to 1998 here as well
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)
					

计算消耗时间

The following examples show how to determine the elapsed time between two JavaScript dates in milliseconds.

Due to the differing lengths of days (due to daylight saving changeover), months, and years, expressing elapsed time in units greater than hours, minutes, and seconds requires addressing a number of issues, and should be thoroughly researched before being attempted.

// Using Date objects
let start = Date.now()
// The event to time goes here:
doSomethingForALongTime()
let end = Date.now()
let elapsed = end - start // elapsed time in milliseconds
					
// Using built-in methods
let start = new Date()
// The event to time goes here:
doSomethingForALongTime()
let end = new Date()
let elapsed = end.getTime() - start.getTime() // elapsed time in milliseconds
					
// To test a function and get back its return
function printElapsedTime(fTest) {
  let nStartTime = Date.now(),
      vReturn = fTest(),
      nEndTime = Date.now()
  console.log(`Elapsed time: ${ String(nEndTime - nStartTime) } milliseconds`)
  return vReturn
}
let yourFunctionReturn = printElapsedTime(yourFunction)
					

注意: In browsers that support the Web Performance API 's high-resolution time feature, Performance.now() can provide more reliable and precise measurements of elapsed time than Date.now() .

获取从 ECMAScript 纪元起的秒数

let seconds = Math.floor(Date.now() / 1000)
					

In this case, it's important to return only an integer—so a simple division won't do. It's also important to only return actually elapsed seconds. (That's why this code uses Math.floor() ,和 not Math.round() .)

规范

规范
ECMAScript (ECMA-262)
The definition of 'Date' in that specification.

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
Date Chrome 1 Edge 12 Firefox 1 IE 3
3
ISO8601 Date Format is not supported in Internet Explorer 8 or earlier.
Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
Date() 构造函数 Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
UTC Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getDate Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getDay Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getFullYear Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getHours Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getMilliseconds Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getMinutes Chrome 1 Edge 12 Firefox 1 IE 4 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getMonth Chrome 1 Edge 12 Firefox 1 IE 4 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getSeconds Chrome 1 Edge 12 Firefox 1 IE 4 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getTime Chrome 1 Edge 12 Firefox 1 IE 4 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getTimezoneOffset Chrome 1 Edge 12 Firefox 1 IE 5 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCDate Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCDay Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCFullYear Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCHours Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCMilliseconds Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCMinutes Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCMonth Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getUTCSeconds Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
getYear 弃用 Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
now Chrome 5 Edge 12 Firefox 3 IE 9 Opera 10.5 Safari 4 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 14 Safari iOS 4 Samsung Internet Android 1.0 nodejs 0.1.100
parse Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
parse :ISO 8601 格式 Chrome 6 Edge 12 Firefox 4 IE 9 Opera 6 Safari 5.1 WebView Android ≤37 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 5.1 Samsung Internet Android 1.0 nodejs 0.12
setDate Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setFullYear Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setHours Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setMilliseconds Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setMinutes Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setMonth Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setSeconds Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setTime Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setUTCDate Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setUTCFullYear Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setUTCHours Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setUTCMilliseconds Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setUTCMinutes Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setUTCMonth Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setUTCSeconds Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
setYear 弃用 Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toDateString Chrome 1 Edge 12 Firefox 1 IE 5.5 Opera 5 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toGMTString 弃用 Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toISOString Chrome 3 Edge 12 Firefox 1 IE 9 Opera 10.5 Safari 5 WebView Android ≤37 Chrome Android 18 Firefox Android 4 Opera Android 11 Safari iOS 4.2 Samsung Internet Android 1.0 nodejs 0.1.100
toJSON Chrome 3 Edge 12 Firefox 1 IE 8 Opera 10.5 Safari 5 WebView Android ≤37 Chrome Android 18 Firefox Android 4 Opera Android 11 Safari iOS 4.2 Samsung Internet Android 1.0 nodejs 0.1.100
toLocaleDateString Chrome 1 Edge 12 Firefox 1 IE 5.5 Opera 5 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toLocaleDateString : IANA time zone names in timeZone option Chrome 24 Edge 14 Firefox 52 IE No Opera 15 Safari 6.1 WebView Android 4.4 Chrome Android 25 Firefox Android No Opera Android 14 Safari iOS 7 Samsung Internet Android 1.5 nodejs 0.12
toLocaleDateString.locales Chrome 24 Edge 12 Firefox 29 IE 11 Opera 15 Safari 10 WebView Android 4.4 Chrome Android 25 Firefox Android 56 Opera Android 14 Safari iOS 10 Samsung Internet Android 1.5 nodejs 13.0.0
13.0.0
部分支持 0.12
Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the function silently falls back to en-US . To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
toLocaleDateString.options Chrome 24 Edge 12 Firefox 29 IE 11 Opera 15 Safari 10 WebView Android 4.4 Chrome Android 25 Firefox Android 56 Opera Android 14 Safari iOS 10 Samsung Internet Android 1.5 nodejs 0.12
toLocaleString Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toLocaleString : IANA time zone names in timeZone option Chrome 24 Edge 14 Firefox 52 IE No Opera 15 Safari 6.1 WebView Android 4.4 Chrome Android 25 Firefox Android No Opera Android 14 Safari iOS 7 Samsung Internet Android 1.5 nodejs 0.12
toLocaleString.locales Chrome 24 Edge 12 Firefox 29 IE 11 Opera 15 Safari 10 WebView Android 4.4 Chrome Android 25 Firefox Android 56 Opera Android 14 Safari iOS 10 Samsung Internet Android 1.5 nodejs 13.0.0
13.0.0
部分支持 0.12
Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the function silently falls back to en-US . To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
toLocaleString.options Chrome 24 Edge 12 Firefox 29 IE 11 Opera 15 Safari 10 WebView Android 4.4 Chrome Android 25 Firefox Android 56 Opera Android 14 Safari iOS 10 Samsung Internet Android 1.5 nodejs 0.12
toLocaleTimeString Chrome 1 Edge 12 Firefox 1 IE 5.5 Opera 5 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toLocaleTimeString : IANA time zone names in timeZone option Chrome 24 Edge 14 Firefox 52 IE No Opera 15 Safari 6.1 WebView Android 4.4 Chrome Android 25 Firefox Android No Opera Android 14 Safari iOS 7 Samsung Internet Android 1.5 nodejs 0.12
toLocaleTimeString.locales Chrome 24 Edge 12 Firefox 29 IE 11 Opera 15 Safari 10 WebView Android 4.4 Chrome Android 25 Firefox Android 56 Opera Android 14 Safari iOS 10 Samsung Internet Android 1.5 nodejs 13.0.0
13.0.0
部分支持 0.12
Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the function silently falls back to en-US . To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
toLocaleTimeString.options Chrome 24 Edge 12 Firefox 29 IE 11 Opera 15 Safari 10 WebView Android 4.4 Chrome Android 25 Firefox Android 56 Opera Android 14 Safari iOS 10 Samsung Internet Android 1.5 nodejs 0.12
toSource 非标 Chrome No Edge No Firefox 1 — 74
不支持 1 — 74
Starting in Firefox 74, toSource() is no longer available for use by web content. It is still allowed for internal and privileged code.
IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android 4 Opera Android No Safari iOS No Samsung Internet Android No nodejs No
toString Chrome 1 Edge 12 Firefox 1 IE 3 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toTimeString Chrome 1 Edge 12 Firefox 1 IE 5.5 Opera 5 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
toUTCString Chrome 1 Edge 12 Firefox 1 IE 4 Opera 4 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
valueOf Chrome 1 Edge 12 Firefox 1 IE 4 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100
@@toPrimitive Chrome 47 Edge 15 Firefox 44 IE No Opera 34 Safari 10 WebView Android 47 Chrome Android 47 Firefox Android 44 Opera Android 34 Safari iOS 10 Samsung Internet Android 5.0 nodejs 6.0.0

图例

完整支持

完整支持

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. 标准内置对象
  2. Date
  3. 方法
    1. Date.UTC()
    2. Date.now()
    3. Date.parse()
    4. Date.prototype.getDate()
    5. Date.prototype.getDay()
    6. Date.prototype.getFullYear()
    7. Date.prototype.getHours()
    8. Date.prototype.getMilliseconds()
    9. Date.prototype.getMinutes()
    10. Date.prototype.getMonth()
    11. Date.prototype.getSeconds()
    12. Date.prototype.getTime()
    13. Date.prototype.getTimezoneOffset()
    14. Date.prototype.getUTCDate()
    15. Date.prototype.getUTCDay()
    16. Date.prototype.getUTCFullYear()
    17. Date.prototype.getUTCHours()
    18. Date.prototype.getUTCMilliseconds()
    19. Date.prototype.getUTCMinutes()
    20. Date.prototype.getUTCMonth()
    21. Date.prototype.getUTCSeconds()
    22. Date.prototype.getYear()
    23. Date.prototype.setDate()
    24. Date.prototype.setFullYear()
    25. Date.prototype.setHours()
    26. Date.prototype.setMilliseconds()
    27. Date.prototype.setMinutes()
    28. Date.prototype.setMonth()
    29. Date.prototype.setSeconds()
    30. Date.prototype.setTime()
    31. Date.prototype.setUTCDate()
    32. Date.prototype.setUTCFullYear()
    33. Date.prototype.setUTCHours()
    34. Date.prototype.setUTCMilliseconds()
    35. Date.prototype.setUTCMinutes()
    36. Date.prototype.setUTCMonth()
    37. Date.prototype.setUTCSeconds()
    38. Date.prototype.setYear()
    39. Date.prototype.toDateString()
    40. Date.prototype.toGMTString()
    41. Date.prototype.toISOString()
    42. Date.prototype.toJSON()
    43. Date.prototype.toLocaleDateString()
    44. Date.prototype.toLocaleString()
    45. Date.prototype.toLocaleTimeString()
    46. Date.prototype.toSource()
    47. Date.prototype.toString()
    48. Date.prototype.toTimeString()
    49. Date.prototype.toUTCString()
    50. Date.prototype.valueOf()
    51. Date.prototype[@@toPrimitive]
  4. 继承:
  5. Function
  6. 特性
    1. Function.arguments
    2. Function.caller
    3. Function.displayName
    4. Function.length
    5. Function.name
  7. 方法
    1. Function.prototype.apply()
    2. Function.prototype.bind()
    3. Function.prototype.call()
    4. Function.prototype.toSource()
    5. Function.prototype.toString()
  8. Object
  9. 特性
    1. Object.prototype.__proto__
    2. Object.prototype.constructor
  10. 方法
    1. Object.prototype.__defineGetter__()
    2. Object.prototype.__defineSetter__()
    3. Object.prototype.__lookupGetter__()
    4. Object.prototype.__lookupSetter__()
    5. Object.prototype.hasOwnProperty()
    6. Object.prototype.isPrototypeOf()
    7. Object.prototype.propertyIsEnumerable()
    8. Object.prototype.toLocaleString()
    9. Object.prototype.toSource()
    10. Object.prototype.toString()
    11. Object.prototype.valueOf()
    12. Object.setPrototypeOf()

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1