开发者

Get different timezones with javascript

Im using this clock plugin: http://designxcore.com/stock/CodeCanyon/clock/main/index.html

I have four different clocks on the website I wish to display.. The clocks should display the time in: London, New York, Hong Kong, Tokyo

However, this plugin takes the time that is on a persons local computer. How can i set it to displ开发者_JS百科ay the different timezones for the cities i wish to display ?


I quite sure this will get you going:

JS World Clock I don't think it address the your time-zone issues, but as I said, I'll get you going...

BTW: I would for this recommend the use of PHP specifically the date() function!

Good luck!


I don't know how can the plugin display four different clocks, but in JavaScript, you can use the Date constructor to create separate date objects for different timezones, all you need is to pass a "proper date string" while initializing, for example:

new Date( "HongKong DateTime String" );
new Date( "Tokyo Date Time String" );

So, assuming in server side you'll have the information of the current time in those locations, so all you need to do is format that to the date format which JavaScript understands and write them in the page and use accordingly.

For more information you can check out this page:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

Hope it helps


by using this you can always get your local time converted into a particular timezone

 let Accepted_time = new Date();
 const option={ timeZone: 'Asia/Hong_Kong' , hour12:false }

 console.log(Accepted_time.toLocaleTimeString('zh-HK',option))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜