Java - 查找正在使用的 tzdata 版本,无论 JRE 版本如何

2022-01-16 00:00:00 timezone java

我们有一个简单的实用程序应用程序,它可以读取 JRE 中使用的所有时区数据,并将其全部显示在一个简单的表格中.我们需要为即将发布的产品版本使用旧版本的 JRE (6_24)(显然是由于其他问题),但我们还需要在该版本中包含较新的时区更新(否则将包含在 6_29).我们已经打包了一个将要安装的私有 JRE,因此使用 TZUpdater 工具 不是问题 - 问题是读取/验证哪个版本的 tzdata(例如 tzdata2010o、tzdata2011k)正在使用实用程序应用程序读取(即,在运行应用程序的 JRE 中使用的版本).该应用当前在标题栏中显示 JRE 版本,但随着时区更新,这已不足以确定正在使用的 时区数据 版本.p>

我查看了 时区 类,但它似乎没有提供此信息 - 也许有一个系统属性包含此信息?TZUpdater 工具知道正在使用哪个版本,因此它必须在某个地方可用 - 我无法想象他们会分析确定更新工具中正在使用哪个版本...有人知道在哪里可以找到此信息吗?

解决方案

在我的一个 JRE 中,JRE_PATHlibzi 中有一个名为 ZoneInfoMappings 的文件.在第一行,它显示了您要查找的数据.

我将寻找一种不那么骇人听闻的方式,如果我发现了什么,我会更新答案.

更新:似乎没有 API 可以获取这些数据.但是,sun.util.calendar.ZoneInfoFile 类中的代码显示了如何解析它.

We have a simple utility app that reads all the time zone data used in a JRE and displays it all in a simple table. We need to use an older version of the JRE (6_24) for an upcoming product release (due to other issues apparently), but we also need to include newer time zone updates in that release (that would otherwise be included in, say, 6_29). We're already packaging a private JRE that will be installed, so getting the time zone updates into that private JRE using the TZUpdater tool is not the issue - The issue is reading/verifying which version of the tzdata (e.g. tzdata2010o, tzdata2011k) is being read with the utility app (i.e. which version is being used in the JRE the app is running in). The app currently displays the JRE version in the title bar, but with the time zone updates, that's no longer sufficient to determine which time zone data version is in use.

I've looked into the TimeZone class, but it doesn't seem to provide this information - perhaps there is a system property that holds this info? The TZUpdater tool knows which version is being used, so it must be available somewhere - I can't imagine they would analytically determine which version is in use in the update tool... Anybody know where to locate this info?

解决方案

In one of my JREs, there's a file in JRE_PATHlibzi named ZoneInfoMappings. In the first line it displays the data you are looking for.

I'm going to search for a less hackish way, will update answer if I find something.

UPDATE: Seems that there's no API to get this data. However, the code in the class sun.util.calendar.ZoneInfoFile shows how to parse it.

相关文章