不确定“更简单”,但更正确(因为并非所有时区都相隔一个小时):
// 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>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)