0

I'm currently using my own web service to get the time. The page sends an ajax request and receives a json string that contains the current date and time.

I've looked around on the web and I'm found other servers that allow for a jsonp request to get the time but I don't know how reliable they really are.

Is there a reliable and free service to retrieve the current time that you can recommend?

Thanks.

frenchie
  • 51,731
  • 109
  • 304
  • 510

3 Answers3

5

This gives you the UTC time in JSON format: http://json-time.appspot.com/time.json

This link is mentioned in this thread.

Community
  • 1
  • 1
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
  • yes, I found this one and then I also found a post saying the service was broken. That's why I'm looking for something reliable. – frenchie Jan 14 '12 at 15:53
  • @frenchie Broken how? What's the uptime? – Šime Vidas Jan 14 '12 at 15:55
  • 1
    broken like this: http://stackoverflow.com/questions/7520793/json-time-service-json-time-appspot-com-is-broken-anyone-have-a-replacement – frenchie Jan 14 '12 at 16:01
  • 1
    http://json-time.appspot.com/time.json seems to have been removed and not working anymore – Radu Jul 29 '15 at 21:22
0

You can use Yahoo's getTime API... http://developer.yahoo.com/util/timeservice/V1/getTime.html

This will give you the seconds since the Unix epoch (UTC). All you need to do is offset this to local. I just created a node.js script that does this in windows, here's the gist. https://gist.github.com/3406378

It's worth noting, that this does NOT account for lag/delay, so only accurate to within a second or so. using NTP is probably your best option, but some NTP clients won't change the date/time if you are already off by several minutes. For my use, this was for a computer that had a dead CMOS battery until I could get a replacement.

var resp = JSON.parse(body);
var dtm = new Date(resp.Result.Timestamp * 1000);

Tracker1
  • 19,103
  • 12
  • 80
  • 106
-2

Simply ensure that your server's clock is accurate. Then you can easily write a small script that gives you the UTC time which you can then use to get the time for any timezone. You could even make the script accept an argument to give you the time in a given timezone instead of UTC.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636