How to convert date value to Coordinated Universal Time

Description

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.

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.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window