我试图显示世界各地几个不同城市的时间,我已经搜索和谷歌,甚至使用了这里找到的答案:PHP 或 JavaScript 中的世界时钟 API,但时钟只会显示在表格中。我使用了这个网站的教程:http://www.proglogic.com/code/javascript/time/worldclock.php(除其他外。这似乎是最直接的。)。
我试图让它显示在我的导航栏中,类似于此页面:https://www.blackcard.com/,所以桌子似乎不是一个可行的方法。当然,我可能是错的。
另外,我正在使用 Bootstrap,如果这很重要的话。
如果大家有什么想法请告诉我。
Thanks!
我会用moment.js为了这
你将需要这两个文件:
http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js
http://momentjs.com/downloads/moment-timezone-with-data.min.js
使用 moment.js,您可以执行以下操作:
html:
<div id="myCoolNavBarr"></div>
javascript
//create a "moment" object from the current date/time
//use the timezone functionality to to set the timezone of the "moment"
//specify the format to display just the time
var newYork = moment.tz("America/Los_Angeles").format("h:mm: A");
var london = moment.tz("Europe/London").format("h:mm: A");
var hongKong = moment.tz("Asia/Hong_Kong").format("h:mm: A");
var tokyo = moment.tz("Asia/Tokyo").format("h:mm: A");
//put them to use
$("#myCoolNavBarr").append("NY "+newYork+ " --- LDN " +london+ " --- HK " +hongKong+ " --- TYO " +tokyo)
这是一个工作JsFiddle
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)