Java - find tzdata version to use regardless of JRE version

We have a simple utility application that reads all the time zone data used in the JRE and displays it all in a simple table. We need to use an earlier version of JRE (6_24) for the upcoming version of the product (due to other problems, apparently), but we also need to include new time zone updates in this version (which would otherwise be included, say, in 6_29) . We are already building a private JRE to be installed, so getting time zone updates in this private JRE using TZUpdater is not a problem - The problem is reading / checking which version of tzdata (e.g. tzdata2010o, tzdata2011k) is read using a utility (e.g. which version is used in the JRE in which the application is running). The application currently displays the JRE version in the title bar, but with time zone updates that are no longer sufficient to determine which version of the time zone data is being used.

I looked at the TimeZone class, but it does not seem to provide this information - is there perhaps a system property that contains this information? The TZUpdater tool knows which version is used, so it must be available somewhere - I can’t imagine that they analytically determined which version is used in the update tool ... Does anyone know where to find this information?

+6
source share
4 answers

One of my JRE_PATH\lib\zi has a file in JRE_PATH\lib\zi named ZoneInfoMappings . The first line displays the data you are looking for.

I'm going to look for a less hacky way, will update the answer if I find something.

UPDATE: There seems to be no API to get this data. However, the code in the sun.util.calendar.ZoneInfoFile class shows how to parse it.

+8
source

Here is a hacker thing that worked for me in both IBM and Oracle JRE:

 public static void main(String args[]) throws Exception { File f = new File(System.getProperty("java.home") + File.separator + "lib" + File.separator + "zi" + File.separator + "ZoneInfoMappings"); if (f.exists()) { FileInputStream fis = new FileInputStream(f); byte[] buf = new byte[11]; try { fis.skip(11); fis.read(buf); System.out.print("Olson Database version is "); System.out.println(new String(buf)); } finally { fis.close(); } } } 

My jdk1.6.0_29 jre says tzdata2012i, and my websphere7 JDK says tzdata2011g

You can use Google to find out if your JDK is updated, and which zones have tz changes.

+1
source

In Java 8, you can use ZoneRulesProvider.getVersions("UTC") :

The exact meaning and format of the version depends on the vendor. The version must follow the lexicographical order, so the returned card will have an order from the oldest known rules to the latest available rules. The TZDB group, by default, uses version numbering, consisting of a year followed by a letter, such as "2009e" or "2012f".

Example:

 System.out.println(java.time.zone.ZoneRulesProvider.getVersions("UTC").lastEntry().getKey()); 

In my Oracle Java 8u91, I get:

2016a

+1
source

In windows use

 findstr tzdata <java-home>\lib\zi\ZoneInfoMappings 

The following link and link were useful for a complete understanding of tzdata in the JRE.

http://www.oracle.com/technetwork/java/javase/tzupdater-readme-136440.html

To define TZData on other platforms, see https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/time-zone001.html

0
source

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


All Articles