有没有一种方法可以获取实际的当前UTC时间戳,而不必依赖于可能未在每个客户端上正确设置的客户端时间?
我知道使用JavaScriptgetTime()
可以以毫秒为单位获取UTC时间戳。它独立于客户的时区,但我认为它取决于客户的当前时间。
我正在尝试制作一个实时时钟,以显示真实的UTC时间,因此客户端的时间设置正确与否并不重要。
获取此JSON:
http://json-time.appspot.com/time.json
或者
http://www.timeapi.org/utc/now
如果有,也可以从您自己的服务器上获取。
有关第一个示例(带间隔):
HTML:
<div id="time">Click the button</div>
<button id="gettime">Get the time</button>
JAVASCRIPT(使用JQuery):
$("#gettime").click(function() {
setInterval(ajaxCalltoGetTime, 1000);
});
function ajaxCalltoGetTime() {
$.ajax({
type: "GET",
url: 'http://json-time.appspot.com/time.json',
dataType: 'jsonp'
})
.done(function( msg ) {
$("#time").html(msg.hour + ":" + msg.minute + ":" + msg.second );
});
JSFiddler:http : //jsfiddle.net/op8xdsrv/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句