Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
853 views
in Technique[技术] by (71.8m points)

timezone - 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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...