I am seeking a reliable REST API that can provide world time and time zone information across platforms.
I need the current time as a string. I'd like it to return the result in under a second, regardless of the user's location worldwide.
Among other implementations I want to use this for a consistent countdown timer, to be more accurate than a user's [possibly-inaccurate] computer time. It can be GMT or another time zone, as long as the time zone and offset is specified, like 2012-11-05 16:16:50 EST
.
I would build this API myself, but have concerns of potential latency issues (as well as inelegance) when filtering someone through a whole big software stack like Rails just to return a simple String
.
Excessive latency for users far away from the US east coast would offset the benefit of accuracy that the task requires.
Any suggestions and/or examples are appreciated.
TimezoneDb provides a free API: http://timezonedb.com/api
GenoNames also has a RESTful API available to get the current time for a given location: http://www.geonames.org/export/ws-overview.html.
You can use Greenwich, UK if you'd like GMT.
This API gives you the current time and several formats in JSON - https://market.mashape.com/parsify/format#time. Here's a sample response:
If you're using Rails, you can just make an empty file in the public folder and use ajax to get that. Then parse the headers for the Date header. Files in the Public folder bypass the Rails stack, and so have lower latency.