Configuring time zone

It is essential for Java™ applications that might be distributed across multiple servers with diverse operating systems to employ a uniform time zone to achieve consistency and accuracy in their functions.

Settings for consistency

To accomplish consistent time zone behavior across different operating systems, set the time zone explicitly in the Java virtual machine (JVM) and environment variables.

Run a Java program with a specific time zone on z/OS® by following these steps.

  1. Use the export command to set the time zone to a required value in the shell environment.
    export TZ=<time_zone>
    Replace <time_zone> with the required time zone, such as America/New_York or UTC.
    Note: Follow the Internet Assigned Numbers Authority (IANA) database for time zone codes. The IANA time zone database provides a comprehensive and up-to-date list of time zone identifiers, ensuring compatibility and consistency across different systems.

    To set the time zone to America/New_York, you can use the following command:

    export TZ=America/New_York

    This sets the time zone for the current shell session, and any commands or applications that are run within this session uses the specified time zone.

    If required, set the time zone permanently for future shell sessions. Add the export command to your shell configuration file, such as ~/.bashrc or ~/.zshrc.

  2. When you run the Java application, pass the time zone parameter to ensure that the Java runtime respects the specified time zone. This sets the time zone for the JVM and can be done by using the following command.
    java -Duser.timezone="<time zone>" <java_application_name>

    To set the time zone to America/New_York, you can use the following command:

    java -Duser.timezone=America/New_York MyJavaApplication

Setting both -Duser.timezone and TZ helps align results across operating systems.

POSIX to Olson mappings

Starting from Java Developer Kit (JDK) 11.0.14+ a TZ mapping file is introduced. On z/OS, it includes POSIX to Olson mapping, while on the other operating systems, Olson mappings are used directly. To strictly conform to POSIX standards, use EST5EDT or EST5EDT4,M3.2.0/01:00:00,M11.1.0/02:00:00 to define the Daylight Saving Time (DST) transition rules.

According to the command format, the TZ environment variable must include two required fields, the standard time, such as EST and the offset specifier. Using only EST does not apply daylight savings on z/OS. Hence, it is recommended to use EST5EDT. For more information, see the relevant z/OS documentation for the TZ command format.

POSIX to Olson mappings are supported in IBM® Semeru Runtime® Certified Edition for z/OS. POSIX values such as TZ=CET-1CEST can be converted to Olson time zones such as America/Indianapolis by using the lib/tzmappings file.
Note: Users cannot externally modify the tzmappings file to suit individual needs.