IBM Support

IBM AIX: Java Application Timestamp

Question & Answer


Question

How to change Java Application Timestamp

Answer


Java application timestamp is determined by the timezone of it's JVM.

For cross platform support, Java uses its own timezone IDs in it's time zone database <java-home>/jre/lib/tzmappings (ex: /usr/java8/jre/lib/tzmappings). The tzmappings file contains the OS time zone name mapping to Java time zone names. When naming the time zone, Java uses the naming convention in its timezone "tz" database.

By default, Java application and it's JVM get the timezone information from the Operating system.

The Java application timestamp can be changed by altering the JVM timezone in following ways.


1. Environment variable 

To change the timestamp to a specific timezone, set the environment variable "TZ".  Any Java applications started from that user login session will have the timestamp corresponding to the new timezone.
Example:
  export TZ="Asia/Hong_Kong"

New timezone setting does not affect the Java applications that are already running.


2.  Java Argument

This overrides the environment variable timezone setting.

To change the timezone/timestamp for a specific Java application, start Java application with argument "-Duser.timezone=<timezone ID>" added to Java command line.

Example:
java -Duser.timezone="Asia/Hong_Kong" HelloWorld


3.  Application Runtime

This has precedence over timezone environment variable and Java command line argument setting.

Any thread of a Java application can change the timestamp at runtime by changing it's current default timezone by calling
TimeZone.setDefault

Example:
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Hong_Kong"));



Attachment "CurrentTimeZone.tar" below contains an environment setup script "setupenv.sh" and a Java program "ShowTimeZone.java". The Java program demonstrates how to change the current timestamp at runtime by changing the timezone.



To run the program:
1. Download and  extract the tar file to some directory like "/tmp"
# cd /tmp
# tar -xvf CurrentTimezone.tar
2. Change permissions
# chmod 755 setupenv.sh
# chmod 755 ShowTimeZone.java
3. Run the script:
./setupenv.sh <java-home (ex:/usr/java8)>


Script will compile and run the Java program to output:

Current TimeZone is : Central Standard Time
Date : Thu Jun 25 22:28:17 CDT 2020

New TimeZone is : Hong Kong Time
Date : Fri Jun 26 11:28:17 HKT 2020


To test with a different timezone, replace "Asia/Hong_Kong" in the "ShowTimeZone.java" program with one of the timezone IDs in <java-home>/jre/lib/tzmappings (ex: /usr/java8/jre/lib/tzmappings).

For Java installs not at the latest level,  to verify and update Java timezone database, refer to:
 
For the DST (Daylight Savings Time) information of a timezone, refer to TimeTest.java program at:
MustGather: Incorrect time stamps displayed by an application or in log files

 

SUPPORT:

If additional assistance is required after completing all of the instructions provided in this document, please follow the step-by-step instructions below to contact IBM to open a case for software under warranty or with an active and valid support contract.  The technical support specialist assigned to your case will confirm that you have completed these steps.

a.  Document and/or take screen shots of all symptoms, errors, and/or messages that might have occurred

b.  Capture any logs or data relevant to the situation.

c.  Contact IBM to open a case:

   -For electronic support, please visit the IBM Support Community:
     https://www.ibm.com/mysupport
   -If you require telephone support, please visit the web page:
      https://www.ibm.com/planetwide/

d.  Provide a good description of your issue and reference this technote

e.  Upload all of the details and data to your case

   -You can attach files to your case in the IBM Support Community
   -Or Upload data to IBM testcase server analysis:

    http://www.ibm.com/support/docview.wss?uid=ibm10733581

f.  Click here to submit feedback for this document.


[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG10","label":"AIX"},"Component":"","Platform":[{"code":"PF002","label":"AIX"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

More support for:
AIX

Software version:
All Versions

Operating system(s):
AIX

Document number:
6232448

Modified date:
28 June 2020

UID

ibm16232448

Manage My Notification Subscriptions