The Date.UTC()
method accepts the same parameters as the Date
constructor, but treats them as UTC. It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
Date.UTC(year, month[, day[, hour[, minute[, second[, millisecond]]]]])
year
month
day
hour
minute
second
millisecond
A number representing the number of milliseconds for the given date since January 1, 1970, 00:00:00, UTC.
UTC()
takes comma-delimited date and time parameters and returns the number of milliseconds between January 1, 1970, 00:00:00, universal time and the specified date and time.
Years between 0 and 99 are converted to a year in the 20th century (1900 + year)
; for example, 95 is converted to the year 1995.
The UTC()
method differs from the Date
constructor in two ways.
Date.UTC()
uses universal time instead of the local time.Date.UTC()
returns a time value as a number instead of creating a Date
object.If a parameter is outside of the expected range, the UTC()
method updates the other parameters to accommodate the value. For example, if 15 is used for month, the year will be incremented by 1 (year + 1)
and 3 will be used for the month.
UTC()
is a static method of Date
, so it's called as Date.UTC()
rather than as a method of a Date
instance.
Date.UTC()
The following statement creates a Date
object with the arguments treated as UTC instead of local:
var utcDate = new Date(Date.UTC(2018, 11, 1, 0, 0, 0));
Specification | Status | Comment |
---|---|---|
ECMAScript Latest Draft (ECMA-262) The definition of 'Date.UTC' in that specification. | Draft | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Date.UTC' in that specification. | Standard | |
ECMAScript 5.1 (ECMA-262) The definition of 'Date.UTC' in that specification. | Standard | |
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.0. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | 1 | Yes | Yes | Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
Server | |
---|---|
Node.js | |
Basic support | Yes |
Date.UTC
with fewer than two argumentsWhen providing less than two arguments to Date.UTC
, ECMAScript 2017 requires that NaN
is returned. Engines that weren't supporting this behavior have been updated (see bug 1050755, ecma-262 #642).
Date.UTC(); Date.UTC(1); // Safari: NaN // Chrome/Opera/V8: NaN // Firefox <54: non-NaN // Firefox 54+: NaN // IE: non-NaN // Edge: NaN
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC