How Does Javascript Know The Time Zone Of A Date In Milliseconds?
The following code when executed using w3schools' interactive js environment (here): var d1=new Date(1306796400000); document.write('Original form: ' + d1); displays the following
Solution 1:
There is no special flag. It's just Daylight Savings in effect.
Solution 2:
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.
Solution 3:
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 = newDate(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"
Solution 4:
It does not. It uses local timezone information, including DST transition date. Hence the difference in
javascript:alert([newDate(1306796400000),newDate(1231977600000)].join('\n'))
Set your locale to DST-less timezone and the difference will disappear.
Post a Comment for "How Does Javascript Know The Time Zone Of A Date In Milliseconds?"