problem with daylight saving time and java applications on Ubuntu server 16.04

Asked

Viewed 1,184 times

2

This weekend we had the change to summer time here in my region, I have some machines running Ubuntu server 16.04 with java applications.

All of them with JBOSS, POSTGRES for one application and another with GLASSFISH, MYSQL.

If I type the command #date on the server it returns me the correct date, already adjusted for daylight saving time, but when saving the records in the applications they get the wrong date!

For example: Now they are 12:45 if I record any records in any of the applications it records as 11:45.

I believe it is a problem with java, has anyone ever been there? or knows how to solve?

I use the OPEN JDK 1.7.0_95

  • This can be database too

  • Do you have a variable that stores the time in java before sending it to the database? what are the date settings for your database?

  • I have no variable I simply use new Date(); before the summer time change was all right

2 answers

2

I went through the same problem and solved with the following:

sudo java -jar tzupdater.jar  -l https://data.iana.org/time-zones/releases/tzdata2018e.tar.gz
  • Then restart the java application and check the date.

Besides, I created a playbook to update the container JVM.

  • Just one detail: the version 2018e of TZDATA is not the most current. You can consult the iana’s website and see that currently the latest version is the 2018g. Or you can use the link https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz, that always brings the latest version.

  • Yes, but with Latest I had problems with Centos. So I used 2018e, which worked on both Centos and Debian and Alpine.

2

I just went through this same problem, mainly because the summer time in 2018 was extended until 4 November because of the elections. Java uses its own database to know the time zones and the beginning and end of the STD (daylight saving time), in this case, just update it using the tool Tzupdater of Oracle itself. The problem is just what you described, you type date in the terminal and the date comes correct, however, if you instantiate a date in java and print the time information, comes with an hour less.

After you download tzupdater.jar, just run it as follows:

java -jar tzupdater.jar -l

Remembering that this command requires upgrade (sudo) because it will update the JRE files.

On JDK 7 the command worked smoothly.

On JDK 8, returned error java.lang.Exception: Failed while Parsing file '/tmp/tz.tmp_1/Asia'

In such a case, you need to edit the file and recollect it in tar.gz that it downloads to update. I made a shell script in this other post which makes the necessary file correction and performs the installation next.

I hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.