Javascript Reference - JavaScript UTC() Method








Date.UTC() returns the millisecond of a date in Coordinated Universal Time.

The arguments for Date.UTC()

  • the year,
  • the zero-based month (January is 0, February is 1, and so on)
  • the day of the month (1 through 31),
  • the hours (0 through 23),
  • minutes,
  • seconds,
  • milliseconds

The year and month are required.

If the day of the month isn't supplied, it's assumed to be 1. all other omitted arguments are assumed to be 0.





Browser Support

UTC() Yes Yes Yes Yes Yes

Syntax

Date.UTC(year,month,day,hours,minutes,seconds,millisec)

Parameter Values

Parameter Description
year Required. A four-digit value representing the year, allowing negative values
month Required. An integer representing the month Expected values are 0-11, but other values are allowed:
-1 will be the last month of the previous year
12 will be the first month of the next year
day Required. An integer representing the day of month Expected values are 1-31, but other values are allowed:
0 will be the last hour of the previous month
-1 will be the hour before the last hour of the previous month

If the month has 31 days, 32 will be the first day of the next month

hour Optional. Default 0. An integer representing the hour. Expected values are 0-23, but other values are allowed: -1 will be the last hour of the previous day
24 will be the first hour of the next day
min Optional. Default 0. An integer representing the minutes. Expected values are 0-59, but other values are allowed:
-1 will be the last minute of the previous hour
60 will be the first minute of the next hour
sec Optional. Default 0. An integer representing the seconds Expected values are 0-59, but other values are allowed:
-1 will be the last second of the previous minute
60 will be the first second of the next minute
millisec Optional. Default 0. An integer representing the milliseconds

Expected values are 0-999, but other values are allowed: -1 will be the last millisecond of the previous second
1000 will be the first millisecond of the next second





Return Value

return a number representing the number of milliseconds between the specified date-time and midnight January 1 1970

Example


var aDate = new Date(Date.UTC(2000, 0)); 
console.log(aDate);
//Fri Dec 31 1999 16:00:00 GMT-0800 (Pacific Standard Time)

The code above generates the following result.

Example 2

months are zero-based hours are represented as 0 through 23.


var aDate = new Date(Date.UTC(2021, 5, 4, 12, 21, 55)); 
console.log(aDate);
//Fri Jun 04 2021 05:21:55 GMT-0700 (Pacific Daylight Time)

The code above generates the following result.