Home > other >  Understanding the Date class
Understanding the Date class

Time:10-11

In Javascript/Nodejs I typed x=new Date(2010,0,1) This will mean 1st Jan 2010. But I see 2009-12-31T18:30:00.000Z in the output. What could be the reason for that?
enter image description here

CodePudding user response:

The missing parameters hour, minute and second are initialised to 0, the entire date is assumed to be your timezone (2010-01-01 00:00:00 India time I assume), and the result you see is being output as UTC date. In other words, when it was midnight Jan 1st 2010 in your timezone, it was Dec. 31st 18:30 UTC.

Why it's being output in UTC depends on your method of printing and/or browser used; it's somewhat free to choose how it will output the date.

  • Related