有谁知道一个好的JSON时间服务器? [英] Does anyone know of a good JSON time server?
本文介绍了有谁知道一个好的JSON时间服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用JSON获取当前时间(来自可靠来源)。精确的时间在我的应用程序中是关键任务,所以我不能依赖设备的时间,即使只有一秒钟或两秒钟。
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.
编辑:我并不像精确度那么担心,只是运行该应用的几台设备有相同的时间。
I am not as worried about 'precision' rather just so that several devices running the app have the same time.
推荐答案
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);
});
这篇关于有谁知道一个好的JSON时间服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文