The following code when executed using w3schools' interactive js environment (here):
var d1=new Date(1306796400000);
document.write("Original form: " + d1);
displays the following message:
Original form: Tue May 31 2011 00:00:00 GMT+0100 (GMT Daylight Time)
But this:
var d1=new Date(1231977600000);
document.write("Original form: " + d1);
displays this message:
Original form: Thu Jan 15 2009 00:00:00 GMT+0000 (GMT Standard Time)
I thought that the millisecond value was just milliseconds since 01/01/1970 in UTC.
But it looks like it contains a flag for time zone.
Can anyone say what the millisecond value format is?
Thanks in advance.
There is no special flag. It's just Daylight Savings in effect.
Javascript is executed inside of the user's browser, which in turn, reads the current time zone from user's OS. That's how it can "guess" the proper time zone.
The milliseconds do not contain any such flag. However, the time zone of the date object you create using new Date(n)
is dependent upon the locale in your interpreter/browser. For me:
var d = new Date(1231977600000);
d.toString();
// "Wed Jan 14 2009 17:00:00 GMT-0700 (Mountain Standard Time)"
d.toUTCString();
// "Thu, 15 Jan 2009 00:00:00 GMT"
It does not. It uses local timezone information, including DST transition date. Hence the difference in
javascript:alert([new Date(1306796400000),new Date(1231977600000)].join('\n'))
Set your locale to DST-less timezone and the difference will disappear.