📜 ⬆️ ⬇️

Watch Translation in Russia October 26 and Java

Hello!

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

So, this is a misconception - just upgrading the JDK on Unix to 1.7.0_72 is no good.
Inside the JDK packages there are timezone files (tzdata package), here it is indicated which package in which distribution kit is included and the content of the tzdata package is specified : www.oracle.com/technetwork/java/javase/tzdata-versions-138805.html
')
As you can see, to get an update to Russian time zones, you need at least a package tzdata2014f .
At the same time in the latest versions of JDK there is only tzdata2014c .

How to solve it?

Suppose you are 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 specify Java being used (for example, the one related to the JAVA_HOME variable) to take the timezone files from the tzdata-java package. To do this, it makes sense to erase or rename the directory with the 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 it 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); } } 

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


Update : Thank you all for your valuable comments. For Windows, manual actions are also needed.

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

We run from each JDK version 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 half the software stop on Sunday / Monday.

Source: https://habr.com/ru/post/241411/


All Articles