Javascript 世界时钟仅显示在表中

Javascript World Clock Only Shows in Table

本文关键字:显示 世界 时钟 Javascript      更新时间:2023-09-26

我正在尝试显示来自世界上几个不同城市的时间,我已经搜索和谷歌搜索,甚至使用了这里找到的答案:php或javascript中的World Clock API,但时钟只会显示在表格中。我使用了这个网站的教程:http://www.proglogic.com/code/javascript/time/worldclock.php(除其他外。这个似乎是最直接的。

我正在尝试让它显示在我的导航栏中,类似于此页面:https://www.blackcard.com/,因此表格似乎不是要走的路。当然,我可能是错的。

另外,我正在使用Bootstrap,如果这很重要的话。

如果你们有任何想法,请告诉我。

谢谢!

我会使用 moment.js

为此

您将需要以下两个文件:

http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.jshttp://momentjs.com/downloads/moment-timezone-with-data.min.js

.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