如何使用 momentjs 获取从 UTC 到东部夏令时的电流偏移量?



我正在尝试获取东部夏令时与现在(或任何时候(的UTC相比有多少秒不同。

因此,例如,现在 UTC 与东部夏令时 = 4*3600 = 14400 秒相差 4 小时(领先(。 但在 12 月,这将变为提前 5 小时。

如何以编程方式编写它,以便脚本知道使用 momentjs 运行时有多少秒不同?

谢谢。

例如:

const moment = require('moment-timezone');
const zone = 'US/Eastern';
const utc = 'UTC';
const diff = date => moment.tz(date, zone)
.diff(moment.tz(date, utc), 'hours');
['2017-02-01', '2017-05-01', '2017-08-01', '2017-11-01'].forEach(date => {
console.log(`${date}: ${diff(date)} hours`);
});

输出:

2017-02-01: 5 hours
2017-05-01: 4 hours
2017-08-01: 4 hours
2017-11-01: 4 hours

最新更新