This is a very nasty problem. As long as the user is presented all the time in his time zone (or GMT), you will have no problems. But asking JS to provide the exact local daylight saving time for different places is unpleasant stuff. The browser knows the time in GMT and local time and (thanks to the OS), it also knows when the DST starts locally. But without changing the time zone information of the user system, JS cannot tell when the DST enters another locale. The rules for when a DST takes effect are not only different from country to country, the date may change over time unexpectedly (remember when the North American countries recently moved daylight saving time?). You can probably easily determine the local DST data on your server and report it to the browser. But it is probably impractical to try to fully use it in a browser. Your application may have some kind of DST_changeover_by_locale array, but you need to update it periodically.
[EDIT] There seems to be some confusion about how the JS Date object works in relation to time zones. Here are some useful points:
Time Zone Offsets
// Create a time in winter (Standard time) dt = new Date('Jan 1 2010 12:00:00 GMT-0000'); alert(dt.getTimezoneOffset()); // In Japan right now, users would see "-540" // In New York right now, users would see "300" // Create a time in summer (DST) dt = new Date('Jul 1 2010 12:00:00 GMT-0000'); alert(dt.getTimezoneOffset()); // In Japan right now, users would see "-540" // In New York right now, users would see "240" // NOTE: Japan has no DST while NY does
Local time synchronization
// The following will all return the same time string, which will be // the time according to the user OS time settings and locale alert((new Date('Jun 25 2010 13:30:00 GMT-0230'))); // Newfoundland time alert((new Date('Jun 25 2010 13:00:00 GMT-0300'))); // Atlantic time alert((new Date('Jun 25 2010 12:00:00 GMT-0400'))); // Eastern time alert((new Date('Jun 25 2010 11:00:00 GMT-0500'))); // Central time alert((new Date('Jun 25 2010 10:00:00 GMT-0600'))); // Mountain time alert((new Date('Jun 25 2010 9:00:00 GMT-0700'))); // Pacific time
Timestamps
// If you don't want to work with strings, use numbers instead. // These return the JS timestamp for the same values above. // The value is a *delta*, so it is unaffected by DST. alert((new Date('Jun 25 2010 13:30:00 GMT-0230')).getTime()); // Newfoundland time alert((new Date('Jun 25 2010 13:00:00 GMT-0300')).getTime()); // Atlantic time alert((new Date('Jun 25 2010 12:00:00 GMT-0400')).getTime()); // Eastern time alert((new Date('Jun 25 2010 11:00:00 GMT-0500')).getTime()); // Central time alert((new Date('Jun 25 2010 10:00:00 GMT-0600')).getTime()); // Mountain time alert((new Date('Jun 25 2010 9:00:00 GMT-0700')).getTime()); // Pacific time
source share