Javascript - Date in UTC/GMT


Date.UTC() to create human friendly date value.

Date.UTC() method returns the millisecond representation of a date.

The arguments for Date.UTC() are the year, the zero-based month (January is 0, February is 1, and so on), the day of the month (1 through 31), and the hours (0 through 23), minutes, seconds, and milliseconds of the time.

Of these arguments, only the first two (year and month) are required.

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

//January 1, 2000 at midnight GMT
var y2k = new Date(Date.UTC(2000, 0));

//May 5, 2005 at 5:55:55 PM GMT
var allFives = new Date(Date.UTC(2005, 4, 5, 17, 55, 55));

The preceding example can then be rewritten as this:

//January 1, 2000 at midnight in local time
var y2k = new Date(2000, 0);

//May 5, 2005 at 5:55:55 PM local time
var allFives = new Date(2005, 4, 5, 17, 55, 55);

This code creates the same two dates as the previous example, but this time both dates are in the local time zone as determined by the system settings.