Java and AIX Time Zones

From Wikistix
(Redirected from Java and AIX Timezones)

Note: As of AIX 6.1, time zones are now defined using the Olson time zone library, and no longer need to use the POSIX format described below.


Unlike some other Unices, AIX time zone rules are statically configured and are not built by zic. The time zone rule is defined by the exported environment variable TZ (usually found in /etc/environment), and for Sydney, Australia, we use the value:

EST-10EDT,M10.1.0/02:00:00,M4.1.0/03:00:00

The two labels, "EST" and "EDT", are actually arbitrary strings that may have any value. The definition of all the various fields may be found in the AIX environment file man page. IBM's packaged versions of Java above 1.2 include a table to map the above labels into a longer (appears to be zic style) time zone rule name. For example, Sydney Australia is:

Australia/Sydney

However, what are the short labels that map to Sydney? "EST" selects American "Eastern Standard Time". In fact, the appropriate rule to map to Sydney is:

EET-10EETDT

This mapping of the short versions to the longer strings is deprecated, and should not be used. There are two ways to do this properly:

  1. Export the environment variable TZ=Australia/Sydney prior to starting the JVM. The disadvantage of this method is that any external process initiated by Java will have this TZ value, and the standard C library will default to GMT.
  2. Set the correct time zone from within Java. This means the existing AIX value of TZ will be unchanged, and continue to work as before.

To set the time zone in Java, use the following code fragment:

TimeZone.setDefault(TimeZone.getTimeZone("Australia/Sydney"));

For a full list of available Java time zones, see the file:

$JAVAHOME/jre/lib/tzmappings

However, the best method may be to create a custom Java time zone definition as described in Java, Time Zones and Daylight Savings changes, allowing full control over all aspects of the definition.

See Also