Web service - current time zone for a city?

2019-01-01 08:44发布

Is there a web service of some sort (or any other way) to pull a current time zone settings for a (US) city. For the parts of the country that don't follow the Daylight Saving Time and basically jump timezones when everyone else is switching summer/winter time... I don't fancy creating own database of the places that don't follow DST. Is there a way to pull this data on demand?

I need this for the database server (not for client workstations) - there entities stored in the database that have City, State as properties. I need know current timezone for these entities at any moment of time.

10条回答
路过你的时光
2楼-- · 2019-01-01 09:04

I found a free downloadable database here: http://citytimezones.info/

[edit] ... but more accurate information (including sources) based on the Olson DB can be found here: http://en.wikipedia.org/wiki/Tz_database

查看更多
何处买醉
3楼-- · 2019-01-01 09:06

earthtools.org provides a free web service to get the time zone from a city here:

http://www.earthtools.org/webservices.htm#timezone

You just pass in the long/lat values like this: (This is for New York)

http://www.earthtools.org/timezone-1.1/40.71417/-74.00639


EDIT:

It seems like earthtools has been shut down. A good alternative (That did not exist in 2008 when this question was answered) is the Google Time Zone API. To use it you must first activate the Time Zone API on your account. It is free if you stay below these limits:

  • 2500 requests per 24 hour period.
  • 5 requests per second.

The documentation is available on Google Developers.

查看更多
余生无你
4楼-- · 2019-01-01 09:08
ら面具成の殇う
5楼-- · 2019-01-01 09:17

In case anyone should bump into this question.

  • You could use Google API to search for an address. That returns latitude / logitude. With those values in hand, you can find the closest timezone using e.g. PHP.

  • Or you can use an API like timezoneapi.io (I'm behind that) which enables you to search for an address / city / country. It returns the address, the timezone information and the current date/time for that given timezone.

https://timezoneapi.io/developers/address

查看更多
高级女魔头
6楼-- · 2019-01-01 09:22

We encountered same issue and, alongside the great suggestions above, Google appears to have two complementary APIs, one for Time Zone from geocode (latitude/longitude) data and the geocode API.

For example, to get the time zone and offset for San Francisco:

1) Convert the city to a geocoded location:

http://maps.googleapis.com/maps/api/geocode/json?address=San%20Francisco,+CA&sensor=false

The geocoded location is in the JSON return data:

"location": {
    "lat":  37.77492950,
    "lng": -122.41941550
}

2) Convert the geocoded location to a local timezone and offset, if any:

https://maps.googleapis.com/maps/api/timezone/json?location=37.77492950,-122.41941550&timestamp=1331161200&sensor=false

Which returns the current time zone information:

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

Time zones for a region can change for a variety of reasons. So it is a good idea to find an authoritative server-based solution and not cache. For more information see Wikipedia's Time Zone article.

查看更多
裙下三千臣
7楼-- · 2019-01-01 09:27

Geonames.org has a wonderful set of worldly data that's available via webservice or download:

http://www.geonames.org/export/ws-overview.html

In particular

http://www.geonames.org/export/web-services.html#timezone

.

查看更多
登录 后发表回答