Javascript Date UTC()

Introduction

The Date.UTC() method accepts parameters similar to the Date constructor and 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]]]]]])

Parameters

Name Optional Meaning
year No A full year.
month Yes An integer between 0 (January) and 11 (December) representing the month.
dayYesAn integer between 1 and 31 representing the day of the month. If omitted, defaults to 1.
hour Optional An integer between 0 and 23 representing the hours. If omitted, defaults to 0.
minute Optional An integer between 0 and 59 representing the minutes. If omitted, defaults to 0.
second Optional An integer between 0 and 59 representing the seconds. If omitted, defaults to 0.
millisecond Optional An integer between 0 and 999 representing the milliseconds. If omitted, defaults to 0.

The following statement creates a Date object with the arguments treated as UTC instead of local:

let utcDate = new Date(Date.UTC(2018, 11, 1, 0, 0, 0));
console.log(utcDate);

Return the number of milliseconds between a specified date and midnight January 1 1970:

var d = Date.UTC(2012, 02, 30);
console.log(d);

Create a date object using UTC time instead of local time:

var d = new Date(Date.UTC(2012, 02, 30));
console.log(d);



PreviousNext

Related