Get the recipe of your success


Handling daylight saving time using JavaScript

In Windows Internet Explorer 9 and previous versions of Windows Internet Explorer, dates are customized by applying the ECMAScript specification's rules for storing daylight saving time adjusted times internally. To improve accuracy, especially with dates in the past (historical dates), Internet Explorer 10 relies on the system's rules for storing daylight saving time adjusted times. This topic contains the following sections:

A webpage that manipulates dates in JavaScript worked as expected in Internet Explorer 9, but no longer produces the same results (or functions incorrectly) in Internet Explorer 10.

The daylight saving time-adjusted time that is produced by Internet Explorer 10 (in Standards mode) differs from that produced by Internet Explorer 9 as shown here:

// Browser is running in Pacific Standard Time zone
// IE10 (Standards mode)
>> new Date(Date.parse("3/31/2000")).toUTCString() "Fri, 31 Mar 2000 07:00:00 UTC" // IE9 (Standards mode) and previous versions of IE
>> new Date(Date.parse("3/31/2000")).toUTCString() "Fri, 31 Mar 2000 08:00:00 UTC"

Though Internet Explorer 10 relies on Windows for daylight saving time adjustments, developers should be aware that some common practices might produce different results in Internet Explorer 10 in Standards mode than in other browsers or earlier versions of Internet Explorer.

For the time zones in which the daylight saving time transition happens at midnight (the clock goes backward), the system time actually transitions 1 millisecond (ms) before the transition boundary. By transitioning 1 ms before, Windows is still within the same day when the daylight

saving time transition happens, but moves the clock backward in an already daylight saving time-transitioned state. This behavior is present in Windows 7 and later.

This sample code attempts to detect a transition from Brasilia Summer Time (BRST) to Brasilia time (BRT) on February, 25, 2012 (that is, the end of Daylight saving time) while the browser is running in the Brasilia time zone.

varmilliSeconds = 0;varoffSet1 =newDate(2012, 01, 25, 24, 00, 00, milliSeconds).getTimezoneOffset();varoffSet2 =newDate(2012, 01, 25, 24, 00, 00, milliSeconds-1).getTimezoneOffset();// Check the offset 1 ms before 
offSet1 != offSet2 ? alert( "dstBoundary" ) : alert( "non-dstBoundary" ); 

Because the system actually transitions 1 ms before the daylight saving time boundary, this example would produce the alert "non-dstBoundary" in Internet Explorer 10 in Standards mode. Checking the offset 2 milliseconds before would correctly produce the alert "dstBoundary".

Internet Explorer 9 and earlier don't accurately adjust for daylight saving time. In Internet Explorer 9, the example produces the alert "non-dstBoundary" at both 1 and 2 milliseconds before the daylight saving time boundary.

If your code calculates historical dates in your web applications, or has custom logic to work around the inaccuracies of the browser date calculation, make sure that the custom logic still works properly when upgrading web applications to work on Internet Explorer 10.

Related topics

IE Test Drive: Exploring Historic Dates
IE Blog: Advancing Historical Date and Time Calculations in IE10, Windows 8 and the ECMAScript Standard

Category: Savings

Similar articles: