用JavaScript显示当地时间(洛杉矶或太平洋)和纽约的时间?

时间:2015-09-13 07:59:56

标签: javascript jquery timezone

我对我的作业有疑问。

如果我要显示来自不同时区位置的时区,您如何插入JavaScript以显示当地时间(洛杉矶或太平洋)和纽约的时间?

1 个答案:

答案 0 :(得分:0)

你最好的选择是以任何方式手动实现,但要使用现成的库。使用Moment Timezone

var now = moment(); // current timestamp, using your machine's time zone
var nowLA = now.tz('America/Los_Angeles'); // converted to LA time zone
var nowNY = now.tz('America/New_York'); // converted to NY time zone

然后,您可以使用Moment提供的任何格式进行打印,例如

now.format('MMMM Do YYYY, h:mm:ss a');  // September 13th 2015, 10:43:17 am
相关问题