Is there a time server that offers an API that i can grab the current eastern time from?

前端 未结 3 1759
说谎
说谎 2021-01-21 09:29

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

3条回答
  •  时光说笑
    2021-01-21 10:02

    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!');
    });
    

提交回复
热议问题