Java, Time Zones and Daylight Savings changes

From Wikistix

Java does not rely on the Operating System for time zone rules. Instead, it ships with rules compiled into the runtime libraries. This means that any changes made to daylight savings rules (like those made in Australia for the Commonwealth Games 2006) will require patches to the Java installation, or programs that are sensitive to time will require source code modifications and recompilation.

Apart from the IBM WebSphere patches at the below link, I am unable to find any other patches relating to JRE.

To fix a program, code similar to the following should be placed into the initialisation routines:

java.util.TimeZone.setDefault(new java.util.SimpleTimeZone(
    10 * 3600 * 1000,
    "Australia/Sydney",
    java.util.Calendar.OCTOBER, 1, java.util.Calendar.SUNDAY,
    2 * 3600 * 1000,
    java.util.Calendar.APRIL, 1, java.util.Calendar.SUNDAY,
    3 * 3600 * 1000,
    1 * 3600 * 1000));

This defines the default time zone rule to be based on the Java Australia/Sydney time zone, but to start daylight savings at 2 AM standard time on the first Sunday in October, and end at 3 AM daylight time (2 AM standard time) on the first Sunday in April.

The TimeTest.java source code may be used as a starting point for experimentation.

I have checked the above information on native Java versions from 1.2.2 through 1.4.2, on Windows, AIX, Solaris, Linux and Darwin (Mac OS X), and also Kaffe 1.4.2 on NetBSD.

Update 2006-12-04: Beginning with Java 1.4, Java on some platforms (eg Win32, but not AIX) ship with binary time zone files built from the freely available Olson tzdata source files. These binary files can be found in <java_home>/lib/zi/ and may be built from source using the javazic tool whose source is contained in the JDK source packages.

See Also