Time change in Russia on October 26 and Java

Hello!

Many familiar programmers believe that in order to transfer the clock in Java to the new Moscow time zone (which will already occur on October 26, the Europe / Moscow time zone will become GMT + 3, not GMT + 4, as now all other Russian time zones too ), it is enough to put updates on Windows, and on Unix - JDK version 1.7.0_72 (in the article we are talking about JDK7, but the information is relevant for any branch, this applies to 5, 6, and 8).

So, this is a misconception - just upgrading the JDK on Unix to 1.7.0_72 is not good.
Inside JDK packages there are timezone files (tzdata package), here it is indicated which package is included in which distribution package and tzdata content of packages is indicated: www.oracle.com/technetwork/java/javase/tzdata-versions-138805.html

As you can see, to get an update to Russian time zones, you need a package of at least tzdata2014f .
At the same time, only tzdata2014c is present in the latest JDK versions .

How to solve this?

Suppose you have already configured:

user@host:/home/user$ echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle


Then you just need to install the tzdata-java package separately:

user@host:/home/host$ sudo apt-get install tzdata-java


Then tell Java to use (for example, one that is associated with the JAVA_HOME variable) to take timezone files from the tzdata-java package. To do this, it makes sense to delete or rename the directory with timezone files inside the JDK and put a symbolic link to / usr / share / javazi:

mv $JAVA_HOME/jre/lib/zi $JAVA_HOME/jre/lib/zi-default
ln –s /usr/share/javazi/  $JAVA_HOME/jre/lib/zi

You can check with the following Java code:

import java.util.*;
import java.text.DateFormat;
public class TestMSK {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Europe/Moscow"));
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US);
        df.setCalendar(c);
        c.setTimeInMillis(1413769091L * 1000L);
        if (!df.format(c.getTime()).equals("Monday, October 20, 2014 5:38:11 AM MSK")) {
            System.out.println("FAIL1 - 20 Oct is not in sync ");
            System.out.println(df.format(c.getTime()));
            System.exit(1);
        }
        c.setTimeInMillis(1414633091L * 1000L);
        if (!df.format(c.getTime()).equals("Thursday, October 30, 2014 4:38:11 AM MSK")) {
            System.out.println("FAIL2 - 30 Oct is not in sync");
            System.out.println(df.format(c.getTime()));
            System.exit(2);
        }
        System.out.println("OK");
        System.exit(0);
    }
}

Verification:
user@host:/home/user$ javac -cp . TestMSK.java
user@host:/home/user$
user@host:/home/user$ java -cp . TestMSK
OK


Update : thanks to everyone for the valuable comments. Windows also needs manual actions.

In this case, the tzupdater tool deals with the update - download from here:
www.oracle.com/technetwork/java/javase/downloads/tzupdater-download-513681.html

Run from each version of the JDK that we want to update:
C:\jdk1.7.0_60\bin>.\java.exe -cp . -jar tzupdater.jar -u


I hope that everything will be updated on time and we will not have a half stop of the software on Sunday / Monday.

Also popular now: