获取时数与时差的时差

获取时数与时差的时差,第1张

获取时数与时差的时差

不确定“更简单”,但更正确(因为并非所有时区相隔一个小时):

// get the current time so we know which offset to take (DST is such bullkitten)var now = moment.utc();// get the zone offsets for this time, in minutesvar NewYork_tz_offset = moment.tz.zone("America/New_York").offset(now);var HongKong_tz_offset = moment.tz.zone("Asia/Hong_Kong").offset(now);// calculate the difference in hoursconsole.log((NewYork_tz_offset - HongKong_tz_offset) / 60);<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.1/moment-timezone-with-data-2010-2020.min.js"></script>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5127516.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存