70
48
|
There are too many questions on StackOverflow about resolving a time zone from a location. This community wiki is an attempt at consolidating all of the valid responses.
Please update my answer, or add your own as you see fit.
The Question
Given the latitude and longitude of a location, how does one know what time zone is in effect in that location?
In most cases, we are looking for an IANA/Olson time zone id, although some services may return just a UTC offset, or some other time zone identifier. Please read the timezone tag info for details.
| |||
82
|
Time Zone Location Web Services
Raw Time Zone Geolocation Data
Time Zone Geolocation Implementations
Libraries that call one of the web services
Other Ideas
Please update this list if you know of any others
Also, note that the nearest-city approach may not yield the "correct" result, just an approximation.
Conversion To Windows Zones
Most of the methods listed will return an IANA time zone id. If you need to convert to a Windows time zone, see this post.
Don't use zone.tab
The tz database includes a file called
zone.tab . This file is primarily used to present a list of time zones for a user to pick from. It includes the latitude and longitude coordinates for the point of reference for each time zone. This allows a map to be created highlighting these points. For example, see the interactive map shown on the moment-timezone home page.
While it may be tempting to use this data to resolve the time zone from a latitude and longitude coordinates, consider that these are points - not boundaries. The best one could do would be to determine the closest point, which in many cases will not be the correct point.
Consider the following example:
The two squares represent different time zones, where the black dot in each square is the reference location, such as what can be found in zone.tab. The blue dot represents the location we are attempting to find a time zone for. Clearly, this location is within the orange zone on the left, but if we just look at closest distance to the reference point, it will resolve to the greenish zone on the right.
| ||||||||||||||||
|
5
|
How about this solution for node.js https://github.com/mattbornski/tzwhere
And its Python counterpart: https://github.com/pegler/pytzwhere
| ||||
|
3
|
We at Teleport just started opening up our API's and one of the usecases is also exposing TZ information for coordinates.
For example one could request all our available TZ information for coordinates in following manner:
This would return the following
For the example I used ./jq for JSON parsing.
| ||
0
|
Try this code for use Google Time Zone API from Java with current NTP Time Client and correct UTC_Datetime_from_timestamp convert:
And use it with:
| ||||||||
|
0
|
Ok here is the short Version without correct NTP Time:
And use it with:
| |||
0
|
If you want to use geonames.org then use this code. (But geonames.org is very slow sometimes)
And use it with:
| ||
0
|
by using latitude and longitude get time zone of current location below code worked for me
| ||||
|
-1
|
And here is a good implementation using JSON data: https://github.com/agap/llttz
| ||||
-4
|
If you prefer to avoid a web service, you can retrieve that information from the browser like this:
In my current case it is printing:
Full Date: 27/01/2014 16:53:37 UTC Offset: UTC-3 Country Code Timezone: BRT
Hope it can be helpful.
| ||||
|
"Europe/London"
time zone identifier of the IANA time zone database. – Matt Johnson Aug 17 '14 at 23:34