You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The time zone map library provides a convenient way of determining the relevant time zone for any location on earth.
The map hails from timezone-boundary-builder,
which is derived from OpenStreetMap data. The idea, and the overall design pattern,
comes from Timeshape.
This library seeks to:
Present a clean and simple API.
Be as fast and small as possible, with minimal dependencies, lending itself well to mobile applications.
Expose the region covered by each time zone to enable custom logic.
Handle overlapping time zones deterministically.
Conserve memory by not loading regions that are unnecessary.
Avoid dependencies on Java 8's time library, for mobile as well as legacy applications.
Examples
importus.dustinj.timezonemap.TimeZoneMap;
// Initialize of a region that spans from Germany to Bulgaria.// Takes some time (~1-5 seconds) to initialize, so try and initialize only once and keep it.TimeZoneMapmap = TimeZoneMap.forRegion(43.5, 8.0, 53.00, 26.0);
Stringberlin = map.getOverlappingTimeZone(52.518424, 13.404776).get().getZoneId(); // Returns "Europe/Berlin"Stringprague = map.getOverlappingTimeZone(50.074154, 14.437403).get().getZoneId(); // Returns "Europe/Prague"Stringbudapest = map.getOverlappingTimeZone(47.49642, 19.04970).get().getZoneId(); // Returns "Europe/Budapest"Stringmilan = map.getOverlappingTimeZone(45.466677, 9.188258).get().getZoneId(); // Returns "Europe/Rome"StringadriaticSea = map.getOverlappingTimeZone(44.337, 13.8282).get().getZoneId(); // Returns "Etc/GMT-1"
If you're on Java 8 or above, you can convert the returned time zone into a proper java.util.TimeZone: