How to check and set java timezone on Linux and Windows?


 

In this article I will briefly explain how to check and update java timezone on Linux and Windows servers with simple examples. 

Linux and  Unix Oracle JDK:

Check running java process

# ps  -ef|grep  -v  grep|grep  java|awk '{print $8}'|sort  -rn|uniq
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64/jre/bin/java
java

Check java version

# java -version
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)
[root@casesup ~]# /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64/jre/bin/java -version
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)

Downlod tzupdater and  tzdata

Tzupdater tool (TimeZone Updater) is  provided to allow you update jre and  jdk timezone  libraries to accommodate daylight saving time changes in different countries. Oracle company relies on the  IANA's timezone database. So there will be two compressed files that you need to download  from the  link I added.

Extract files and check tzdata version

# ls  -ld  *
-rw-r--r-- 1 root root 392087 Oct 28 10:39 tzdata2019c.tar.gz
-rw-r--r-- 1 root root 166595 Oct 28 10:54 tzupdater.jar
-rw-r--r-- 1 root root 159058 Oct 28 10:38 tzupdater-2_3_0.zip
# /usr/java/jdk1.8.0_231/bin/java -jar  tzupdater.jar  -v
Usage: java -jar tzupdater.jar options
options:
        -h, --help     Print this message and exit.
        -V, --version  Print tool version, tzdata version in JRE, tzdata version
                       that tool would update to and then exit.
        -l, --location <URL link to tzdata.tar.gz archive file>
                       Compile, test and update JRE timezone data from provided tzdata.tar.gz bundle
                       e.g -l https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz
                       Supported URL protocols : http://, https://, file://
                       If no URL link is provided, tool will use latest IANA tzdata bundle at:
                           https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz
        -f, --force    Force a tzdata update. Use this option if updating to an older tzdata version.
        -v, --verbose  Display detailed messages to stdout.



# /usr/java/jdk1.8.0_231/bin/java -jar  tzupdater.jar  -V 
tzupdater version 2.3.0-b01
JRE tzdata version: tzdata2019b

Update timezone libraries

Online:

Server needs internet access to get latest tzdata file.

# /usr/java/jdk1.8.0_231/bin/java -jar  tzupdater.jar  -l  --verbose 
Using https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz as source for tzdata bundle.
java.home: /usr/java/jdk1.8.0_231/jre
java.vendor: Oracle Corporation
java.version: 1.8.0_231
tzupdater version 2.3.0-b01
JRE tzdata version: tzdata2019b

Offline:

Download  binary and upload to the server under /tmp.

[root@casesup javatimezone]# /usr/java/jdk1.8.0_231/bin/java -jar  tzupdater.jar  -l  file:///tmp/tzdata2019c.tar.gz  --verbose
Outputting tzdb file: /usr/java/jdk1.8.0_231/jre/lib/tzdb.dat.dynamic
Renaming /usr/java/jdk1.8.0_231/jre/lib/tzdb.dat to /usr/java/jdk1.8.0_231/jre/lib/tzdb.dat.tzdata2019b
Renaming /usr/java/jdk1.8.0_231/jre/lib/tzdb.dat.dynamic to /usr/java/jdk1.8.0_231/jre/lib/tzdb.dat
Validating for : tzdata2019c
Validation complete
JRE updated to version : tzdata2019c

Linux Open JDK:

There are two rpm packages are provided by linux distro to update tzdata libraries. 

tzdata-2016j-1.el7.noarch <System tzdata libraries>
tzdata-java-2016j-1.el7.noarch <OpenJDK java tzdata libraries>
# yum update tzdata
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
redhat7_Software                                                                                                                                                                                                     | 4.0 kB  00:00:00     
redhat7_Update                                                                                                                                                                                                       | 4.0 kB  00:00:00     
repo_opt                                                                                                                                                                                                             | 4.0 kB  00:00:00     
repoextra                                                                                                                                                                                                            | 4.0 kB  00:00:00     
(1/2): redhat7_Update/updateinfo                                                                                                                                                                                     | 3.4 MB  00:00:00     
(2/2): redhat7_Update/primary_db                                                                                                                                                                                     | 100 MB  00:00:02     
Resolving Dependencies
--> Running transaction check
---> Package tzdata.noarch 0:2016j-1.el7 will be updated
---> Package tzdata.noarch 0:2019c-1.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================================================
 Package                                               Arch                                                  Version                                                    Repository                                                     Size
============================================================================================================================================================================================================================================
Updating:
 tzdata                                                noarch                                                2019c-1.el7                                                redhat7_Update                                                493 k

Transaction Summary
============================================================================================================================================================================================================================================
Upgrade  1 Package

Total download size: 493 k
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for redhat7_Update
tzdata-2019c-1.el7.noarch.rpm                                                                                                                                                                                        | 493 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Updating   : tzdata-2019c-1.el7.noarch                                                                                                                                                                                                1/2 
  Cleanup    : tzdata-2016j-1.el7.noarch                                                                                                                                                                                                2/2 
  Verifying  : tzdata-2019c-1.el7.noarch                                                                                                                                                                                                1/2 
  Verifying  : tzdata-2016j-1.el7.noarch                                                                                                                                                                                                2/2 

Updated:
  tzdata.noarch 0:2019c-1.el7                                                                                                                                                                                                               

Complete!


[root@eaglemonitorp01 javatimezone]# rpm -qa|grep tzda
tzdata-2019c-1.el7.noarch
tzdata-java-2016j-1.el7.noarch
[root@casesup javatimezone]# yum update  tzdata-java
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package tzdata-java.noarch 0:2016j-1.el7 will be updated
---> Package tzdata-java.noarch 0:2019c-1.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================================================
 Package                                                  Arch                                                Version                                                     Repository                                                   Size
============================================================================================================================================================================================================================================
Updating:
 tzdata-java                                              noarch                                              2019c-1.el7                                                 redhat7_Update                                              187 k

Transaction Summary
============================================================================================================================================================================================================================================
Upgrade  1 Package

Total download size: 187 k
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for redhat7_Update
tzdata-java-2019c-1.el7.noarch.rpm                                                                                                                                                                                   | 187 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : tzdata-java-2019c-1.el7.noarch                                                                                                                                                                                           1/2 
  Cleanup    : tzdata-java-2016j-1.el7.noarch                                                                                                                                                                                           2/2 
  Verifying  : tzdata-java-2019c-1.el7.noarch                                                                                                                                                                                           1/2 
  Verifying  : tzdata-java-2016j-1.el7.noarch                                                                                                                                                                                           2/2 

Updated:
  tzdata-java.noarch 0:2019c-1.el7                                                                                                                                                                                                          

Complete!
[root@casesup javatimezone]# 

# java  -jar  tzupdater.jar  -V
tzupdater version 2.3.0-b01
JRE tzdata version: tzdata2019
# java  -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

 

Windows Oracle JDK:

 

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me