如何使用javascript或jquery获取全局时间(而不是pc时间)? [英] How to get global time(not the pc time) using javascript or jquery?

查看:88
本文介绍了如何使用javascript或jquery获取全局时间(而不是pc时间)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javascript创建一个倒数计时器;我可以使用jQuery.我要的是全球时间而不是PC时间.

I was creating a countdown timer using javascript; I can use jQuery. I want the global time not the PC time.

如何使用javascript或jQuery获取全球时间?

How could I get the global time using javascript or the jQuery?

推荐答案

使用时间API,例如: http://www .timeapi.org/

Use a time API like: http://www.timeapi.org/

<script type="text/javascript">
     function myCallback(json) {
          alert(new Date(json.dateString));
     }
</script>
<script type="text/javascript" src="http://timeapi.org/utc/now.json?callback=myCallback"></script>

您可以从Date对象使用UTC方法: http://www.w3schools. com/jsref/jsref_obj_date.asp

You can use the UTC methods from Date object: http://www.w3schools.com/jsref/jsref_obj_date.asp

var utcDate = new Date(json.dateString);
alert(utcDate.getUTCFullYear() + '-' + utcDate.getUTCMonth() + utcDAte.getUTCDate());

这篇关于如何使用javascript或jquery获取全局时间(而不是pc时间)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆