I have this code:
function getTime(zone, success) {
var url = 'http://json-time.appspot.com/time.json?tz=' + zone,
ud = 'json' + (+new Date());
window[ud]= function(o){
success && success(new Date(o.datetime));
};
}
Which is part of code I had in the app before, it is not functional.
What it is supposed to do it connect to that server and get current time using JSON. I want it to just return the datetime or even better – the current EPOCH time. I am not sure how to modify it to make it work – should I just create a new date var and return it? Like,
var newDate = new Date(o.datetime)
return newDate?
The time on the website is in this object:
{
"tz": "EST",
"hour": 19,
"datetime": "Sun, 04 Mar 2012 19:20:37 -0500",
"second": 37,
"error": false,
"minute": 20
}
If
o.datetimeis a valid date that theDateconstructor can take and parse, you should be able to call the function with a callback and apply any method you like:Further reading: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date