Displaying Author Local Time
4. Daylight Saving
Join the Discussion
More of this Feature
Istead of having to adjust manually on the dates that daylight saving starts and finishes, you can if you wish place code after the dst=0 line to set the daylight saving flag based on the dates that your area goes on and off of daylight savings time. If the dates change each year you may still need to update the script once a year but the date of the update is no longer as critical.
Here (in Sydney) we usually go onto daylight savings time at 2am on the last Sunday in October and back to standard time at 3am on the last Sunday in March. The following code will perform this switch at midnight visitor local time on those dates which is within a day of the correct time for the change. (To be more accurate than this would require about three times as much code which I don't think is worth it in this instance).
var lsm = new Date;
var lso = new Date;
lsm.setMonth(2); // March
lsm.setDate(31);
var day = lsm.getDay();// day of week of 31st
lsm.setDate(31-day); // last Sunday
lso.setMonth(9); // October
lso.setDate(31);
day = lso.getDay();
lso.setDate(31-day);
if (gmt < lsm || gmt >= lso) dst = 1;
You would of course need to change the code to determine the appropriate dates for your local circumstances. Note that the month numbers run 0 = January through 11 = December and not 1 through 12.
Note that the script and the descriptions of the functions that it contains are rewritten from the "Ask Felgall" website with the permission of the copyright owner.

