Home > Back-end >  JavaScript - How to get 1900/01/01 in UTC 0?
JavaScript - How to get 1900/01/01 in UTC 0?

Time:07-23

I have seen that Date.UTC() returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.

If I do new Date(Date.UTC(1900, 0, 1)).toString() I get

Sun Dec 31 1899 23:45:16 GMT-0014 (hora estándar de Europa central)

Why?

Test here:

const date = new Date(1900, 0, 1);
console.log(date.toString())

console.log("==========================");

const date2 = new Date(Date.UTC(1900, 0, 1));
console.log(date2.toString())

CodePudding user response:

toString() will return tour local time based on OS configuration. If you want UTC then use toUTCString()

console.log(new Date(Date.UTC(1900, 0, 1)).toString())
console.log(new Date(Date.UTC(1900, 0, 1)).toUTCString())

  • Related