Is there a database with location -> name of timezone as per IANA Time Zone Database

4.2k Views Asked by At

In my script (PHP), I use the tz database label for each location in my database: http://en.wikipedia.org/wiki/Tz_database

I am entering a whole series of places (countries, provinces, states, cities, etc.) from around the world, and for each, I have found it very difficult to know which label from the IANA Time Zone Database to use.

Searching the location on wikipedia gives me the time offset (UTC+n) and the timezone abbreviation (EST, etc.) but neither helps in knowing which entry to use in the tz database.

E.g.: Washington DC uses, as best as I could figure out, 'America/New_york'.
Dallas, TX uses 'America/Chicago' (unless I'm mistaken!)

There is a small African country for which neither its capital city nor its largest city were in the tz database. Which tz entry to use?

There must be a database somewhere, or a resource which clearly links every location on earth (country, state, province, city, etc.) to a specific entry in the tz database. Where can I find it?

3

There are 3 best solutions below

0
On

One approach you might consider would be to find the latitude and longitude of the location in question.

Then you can look up the applicable time zone for those coordinates using one if the methods described here.

0
On

The best I have found so far is this:
http://twiki.org/cgi-bin/xtra/tzdatepick.html but it only has cities.

E.g. it lists Paris, but it doesn't list France. If a whole country is included within a single timezone (e.g. any city in France would be listed under Europe/Paris) then I'd like to know it.

There is no listing for Idaho (which is split between two zones) and neither for Moscow, Idaho.

I am using the following sources for the US: http://en.wikipedia.org/wiki/List_of_U.S._states_by_time_zone but a lot of guesswork is needed for any state and city.

This list is barely usable but the best I've got so far:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones Mocow, Idaho?
Fort Wayne, Indiana?
Hard to tell from the above list when we don't personally know the said locations.

1
On

combining google map API works fine for example use below API to get location from address. address is "Mountain View, CA, US"

https://maps.googleapis.com/maps/api/geocode/json?address=Mountain+View,+CA,+US&key=YOUR_API_KEY

this URL returns JSON some thing like this

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4224764,
               "lng" : -122.0842499
            },
            "location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.4238253802915,
                  "lng" : -122.0829009197085
               },
               "southwest" : {
                  "lat" : 37.4211274197085,
                  "lng" : -122.0855988802915
               }
            }
         },
         "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

and you can extract location from JSON and call location to time zone API.

API call sample:

 https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=YOUR_API_KEY

that returns JSON like this

{
   "dstOffset" : 0,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Standard Time"
}