Reputation: 91959
There is an excellent answer on how to get TimeZone given a Latitude and Longitude. There is however a comment in the answer as
One thing I've noticed is the lack of any UTC timestamp requirement when determining the time zone. For instance, a long/lat in London is not enough to determine weather the time zone is GMT or BST (British Summer Time / daylight savings). So surely to determine the correct time zone you need lat, long and a UTC timestamp.
Also, there is a wiki, which talks that Java has it's own database for Timezones, which is documented on Oracle website
I am wondering that given a UTC Datetime
, Latitude
and Longitude
, is there a way to leverage the Java's timezone database to get the timezone instead of making API calls?
Any resources/examples?
Upvotes: 2
Views: 6903
Reputation: 241475
The article you referenced shows several libraries that work offline, including one for Java. These libraries look up lat/lon against the tz_world map, then give you back a standard IANA time zone identifier, such as America/New_York
.
Then, you use that identifier with whatever timestamp to convert, using Java libraries or standard Java. The best approach is to use Joda-Time for Java 7 and earlier, and use the new java.time package for Java 8+.
There's not a one-step implementation, because these are two different concerns. You might need both in some cases, but not always.
Upvotes: 2