Ok we have a countdown on our site and I need to do an api call to get the current eastern time. I have this link which is the time I need. Is there any way or any webservice th
I use http://www.timeapi.org/ to get the current time. It can return the date/time in a variety of formats and its free and easy to use. Obviously, the server time is quite easy to get but sometimes that is not an option, which is why I have used this API on a couple occasions. You can use the pure JavaScript method that is listed on their site, but I opted for a jQuery AJAX call :
$.ajax({
type: "GET",
url: 'http://www.timeapi.org/utc/now.json',
dataType: "jsonp",
context: this
}).done(function(data) {
// do stuff
})
.fail(function(){
throw new Error('timeAPI ajax called failed!');
});
Try this: http://worldclockapi.com/api/json/est/now
And you may want to use the JSONP version or some sort of CORS proxy.
The easiest answer is to just get the current time from your server, as this avoids cross-origin issues.
Keep in mind that you still aren't (and can't) guaranteeing second-resolution accuracy. By requesting the time from your server, you're totally at the mercy of network conditions that you can't measure from JavaScript. One client might receive the AJAX time request in tens of milliseconds, while others with low-quality connections might even take tens of seconds.
In fact, in many cases it might be more reliable to use the client's clock since it too will be synced to a reliable time source via NTP. I believe Windows has NTP sync enabled by default. Your best bet might be to make an AJAX request for the server's current time and date, and if the local machine's time is within 20 or so seconds of the server's time, just use local time.