Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know of a good JSON time server?

I need to obtain current time (from a credible source) using JSON. Precise time is mission-critical in my application so I cannot rely on the time of the device, even if it is only a second or two off.

EDIT: I am not as worried about 'precision' rather just so that several devices running the app have the same time.

like image 204
antonpug Avatar asked Feb 28 '12 16:02

antonpug


People also ask

Why do so many APIs use JSON?

It did not require the rather inconvenient “data binding” and “data serialization” steps that were notoriously difficult when using XML-based APIs. Instead, JSON allowed APIs to represent structured data in a way that simply was a better fit for the conceptual universe that most developers live in.

What is the JSON server?

JSON Server is a Node Module that you can use to create demo rest json webservice in less than a minute. All you need is a JSON file for sample data.

Is there any standard for JSON:API response format?

Yes there are a couple of standards (albeit some liberties on the definition of standard) that have emerged: JSON API - JSON API covers creating and updating resources as well, not just responses. JSend - Simple and probably what you are already doing.

Is JSON:API a standard?

JSON:API sets a standard for communication; it expresses how requests to the server should be formatted, and then what the response to the client should be formatted as. Its goal is to optimize HTTP requests by reducing the number of requests needed as well as reducing the size of the packages themselves.


2 Answers

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));
    };
    document.getElementsByTagName('head')[0].appendChild((function(){
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = url + '&callback=' + ud;
        return s;
    })());
}

getTime('GMT', function(time){
    // This is where you do whatever you want with the time:
    alert(time);
});

from here

like image 186
NimChimpsky Avatar answered Sep 25 '22 12:09

NimChimpsky


As of Jan. 07th 2020 http://worldtimeapi.org/ is working fine. we can get current date and time details for specfic time-zone or ip address easily in either json format or plain text format.

http://worldtimeapi.org/api/timezone/America/Santiago

the above url will give you the current date and time details in json for "America/Santiago".

http://worldtimeapi.org/api/timezone/Asia/Kolkata

the above url will give you the current date and time details in json for "Asia/Kolkata".

Request the current time based on your public IP (as JSON):

$ curl "http://worldtimeapi.org/api/ip"

Note: by default, the API returns JSON. Adding a suffix of .txt to any API URL will return a plain-text response, which may be easier to parse on some systems.

like image 25
Suresh P Avatar answered Sep 24 '22 12:09

Suresh P