Web service - current time zone for a city?
来源:互联网 发布:妙趣横生的算法 c 编辑:程序博客网 时间:2024/04/29 12:38
http://stackoverflow.com/questions/55901/web-service-current-time-zone-for-a-city
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.
9 Answers
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.
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×tamp=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.
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
.
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.
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.
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).
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
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/
Google, 2500 free requests per day https://developers.google.com/maps/documentation/timezone/
- Web service - current time zone for a city?
- Time Zone
- Time Zone
- How to get current date time in SharePoint Site Time Zone
- Tips for working with time zone in flex app
- 全面解读:Web service到底是什么?【Zone Yan 转载】
- Resetting time zone
- rails time zone (brown)
- device time zone
- 时区(time zone)
- Change Time zone
- Rails 时区Time Zone
- Web service for attachement
- web service for java
- Puzzel2:Time for a Change
- 解决 web service is not a valid method for this service
- Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab
- timestamp with time zone 和 timestamp with local time zone
- 企业网站首页结构布局几点心得感悟
- 图片 动画
- 不要滥用UNLOGGED table 和 hash index
- Eclipse创建Maven项目
- 深入理解jQuery.css和jQuery.style源码
- Web service - current time zone for a city?
- inputreader到inputdispacther到channel
- 虚拟机磁盘 centos 扩展空间
- 1.冒泡排序
- JAVA EL表达式详细介绍使用手册
- his系统运维日志----1
- codeforces 551 E. GukiZ and GukiZiana
- __NSCFNumber length
- Android 将asserts文件夹内文件写入SD卡中