Web service - current time zone for a city?



http://stackoverflow.com/questions/55901/web-service-current-time-zone-for-a-city

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.

share improve this question
 

9 Answers

up vote 41 down vote accepted

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.

share improve this answer
 
3 
what if we do not know the latitude/longitude information for a city?  –  emaillenin   Feb 25 '11 at 6:45
   
EarthTools is great but since a week it's offset by 4 min. Great but does not seem reliable.  –  Malartre   Oct 18 '11 at 21:49
1 
I add a few issues with earthtools.org especially when DST in involved. I would not recommend this webservice. I found timeanddate.com to be much more accurate, it is not free though.  –  Jérôme R   Mar 7 '12 at 8:57
   
i agree, DST support is very poor :(  –  Patrick Oscity   Mar 11 '12 at 11:48
2 
As of 2015-09-09 it's not working. My app is in danger. How irresponsible!! I know it was free, but how can they just shut it down like that.  –  AtanuCSE   Aug 9 at 10:38

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.

share improve this answer
 
   
Thanks @shanebest for adding the url!  –  Mike Davis   Dec 2 '13 at 22:48  
   
Note, that you can pass non-English city name to the Google Geocode.  –  Alexander   Apr 7 '14 at 11:04

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

.

share improve this answer
 
   
However it doesn't allow to specify date,for which you want to find timezone offset  –  Michael Freidgeim   May 13 '12 at 2:39
   
Hi... Thanks for the answer and it helps me a lot. I need to ask you whether daylight saving time is implemented in it? Let me know as i can't test it now? I need current time from lat long.  –  Sagar Rawal   Dec 12 '12 at 10:01

Earthtool's timezone info is not up to date ... for an instance, the Sri Lankan current offset is +5.5 from GMT but EarthTools shows as +6 which was the old offset before 2005.

I suggest GeoNames.org.

share improve this answer
 

WorldTimeServer.com has what appears to be a comprehensive time zone database, which you can purchase access to in a variety of formats, including a .NET component for Web use.

No connection, just had to research the same thing myself recently.

share improve this answer
 

Simple Offline Library : APTimeZones

In order to find the time zone for a location you can use such as the Google Maps API’s time zone API. Unfortunately this requires you to query a remote service and you are subject to their limits.

Here’s a library rom Alterplay called APTimeZones(Git is attached) that allows you to extract an NSTimeZone from a given location without the need to connect to a remote service. APTimeZonesworks by querying a local listing of time zones (included with the library).

share improve this answer
 
1 
I've rewritten this library in Java, so you can use it on Android devices also: github.com/agap/llttz  –  aga   Oct 16 '14 at 13:37

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

share improve this answer
 
   
I feel, it's not reliable, and required manual download process to refresh information.  –  Michael Freidgeim   Dec 12 '12 at 12:19
   
@MichaelFreidgeim :: I'm not sure what your thinking? Isn't programming mostly a "manual" process? I downloaded that data and loaded it into my own DB once as part of the solution development process and didn't have to do it again after that. - "refresh information" ... again, I am kinda stumped. If I have all the data in my DB and I am only only going off LAT, LONG and the associated timezones don't change, then what is there to refresh? My implementation requires no sort of manual refresh process so I really have no idea what you have in mind.  –  Michael.M   Mar 9 '13 at 17:29  
   
Assumption "the associated timezones don't change" is not correct. In particular, day light saving are changing all the time, so you need to have source of data, that someone maintain and a way (ideally automated) to reload data when the changes happen. I beleive NodaTime noda-time.googlecode.com is a good way to address the problem. See more in stackoverflow.com/questions/2532729/…  –  Michael Freidgeim Mar 10 '13 at 12:37
   
@MichaelFreidgeim: Good point, I never thought of this till now. What I found interesting was the [following article by Oracle (oracle.com/technetwork/java/javase/timezones-137583.html) explaining deployment of Olson timezone data with the JRE. They also have the TZUpdater tool which would solve your "manual" update issue if you are on the Java stack. If you are on Debian or a derivative, you can easily script automated updates (packages.debian.org/sid/tzdata). In fact I dont see any reason why you can't script a solution from any of the many available Olson DB sources  –  Michael.M   Mar 22 '13 at 18:57  

I know this is answered, but I am posting this answer as people might still find it useful - The selected answer does not work successfuly right now.

Google have their own service, which is very reliable and easy to use, and outputs info in JSON format. It even allows for specifying a custom time, e.g get the timezone in 02/02/2013 in Malta.

https://developers.google.com/maps/documentation/timezone/

share improve this answer
 

Google, 2500 free requests per day https://developers.google.com/maps/documentation/timezone/

share improve this answer
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值