Skip to content Skip to sidebar Skip to footer

Javascript World Clock Only Shows In Table

I am trying to display times from a few different cities around the world, and I have searched and Google'd and even used the answer found here: World Clock API in php or in javasc

Solution 1:

I would use moment.js for this

you will need these two files:

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

With moment.js, you could do the below:

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)

Here is a working JsFiddle

Post a Comment for "Javascript World Clock Only Shows In Table"