I know that I can display time for a particular location using only JavaScript (and no web service or external data source), but... I want to avoid using this solution because I don't want to have to account for daylight savings time, and any other factors that make it complicated.
I'm looking for an easier way to display the time and always for a particular city (or zip code, or whatever identifier works...).
For example, I want a page to always say:
The current time in Miami is "X"
(where "X" should be replaced by the current time in Miami)
Is there a web servi开发者_开发技巧ce (or any other method) where I can post some identifier (city name, zip code, etc) and get back the time?
Is there a web service (or any other method) where I can post some identifier (city name, zip code, etc) and get back the time?
I don't know of a single web service that will do the job.
Google's Geocoding API can help. You can feed it a parameter, and it will return certain information, such as the latitude/longitude. Example using a zip code, but I'm sure you can easily put in a city/state pair and make it work.
You can then take that lat/long pair and point it at service like GeoNames. They have a timezone API that takes a lat/long pair and returns quite a bit of information. Example using the lat/long from the zip code.
精彩评论