Date.UTC()
The Date.UTC() method accepts parameters similar to the
Date constructor, but treats them as UTC. It returns the number of
milliseconds since January 1, 1970, 00:00:00 UTC.
Syntax
Date.UTC(year)
Date.UTC(year, monthIndex)
Date.UTC(year, monthIndex, day)
Date.UTC(year, monthIndex, day, hour)
Date.UTC(year, monthIndex, day, hour, minute)
Date.UTC(year, monthIndex, day, hour, minute, second)
Date.UTC(year, monthIndex, day, hour, minute, second, millisecond)
year: Integer value representing the year.
Values from
0to99map to the years1900to1999. All other values are the actual year. See the example.
monthIndexoptional- : An integer between
0(January) and11(December) representing the month. Since ECMAScript 2017 it defaults to0if omitted. (Up until ECMAScript 2016,monthIndexwas a required parameter. As of ES2017, it no longer is.)
- : An integer between
dayoptional- : An integer between
1and31representing the day of the month. If omitted, defaults to1.
- : An integer between
houroptional- : An integer between
0and23representing the hours. If omitted, defaults to0.
- : An integer between
minuteoptional- : An integer between
0and59representing the minutes. If omitted, defaults to0.
- : An integer between
secondoptional- : An integer between
0and59representing the seconds. If omitted, defaults to0.
- : An integer between
millisecondoptional- : An integer between
0and999representing the milliseconds. If omitted, defaults to0.
- : An integer between
Return value
A number representing the number of milliseconds for the given date since January 1, 1970, 00:00:00, UTC.
Description
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 aDateobject.
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 monthIndex, 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.