Zoneinfo TZ is a Java time zone library that parses zoneinfo files and produces a JDK compatible facade for returning time zone information.
The motivations to create this library were to:
The following diagram outlines this library's structure:
The following code illustrates how a file based zoneinfo resource can be loaded:
ZoneFactory factory = new ZoneFactory(); Map<String, AbstractZone> zones = ZoneinfoTimeZone.getZones(); factory.parse(ZoneinfoTimeZoneTest.class.getResourceAsStream("europe"), zones);
To get a time zone you can then obtain it in the regular JDK way:
TimeZone tz = ZoneinfoTimeZone.getTimeZone("Europe/London");
To get an offset given a date you can then:
int offset = tz.getOffset(GregorianCalendar.AD, 2010, Calendar.APRIL, 3, Calendar.SATURDAY, 15 * 60 * 60 * 1000)
This project is an alternative to what has been proposed for time zones in JSR-310 .