[英]Moment/Timezone - converting a date to unix
Why does the following return Fri, 22 Apr 2016 13:01:00 GMT
? 为什么以下代码会返回
Fri, 22 Apr 2016 13:01:00 GMT
?
Should it not be Fri, 22 Apr 2016 17:01:00 GMT
(4 hours added for timezone)? 应该不是
Fri, 22 Apr 2016 17:01:00 GMT
(时区增加4个小时)吗?
var zone = "America/New_York";
var date = 'Fri, 22 Apr 2016 13:01';
$('#ts').text(moment.tz(date, zone).unix()); // 1461330060
// epochconverter.com (1461330060) --> Fri, 22 Apr 2016 13:01:00 GMT ?!!
Edit: updated fiddle . 编辑:更新小提琴 。 If I pass in
Fri, 22 Apr 2016 13:01
it now spits out Fri, 22 Apr 2016 12:01:00 GMT
, so it ignores any DST as expected for UTC, but I'm still confused why it's not returning Fri, 22 Apr 2016 17:01:00 GMT
? 如果我在
Fri, 22 Apr 2016 13:01
通过,它现在会在Fri, 22 Apr 2016 12:01:00 GMT
离开,因此它会忽略UTC预期的任何夏令时,但我仍然感到困惑,为什么它不返回Fri, 22 Apr 2016 17:01:00 GMT
?
I think the problem was using jsfiddle which may be based in US, so moment was using localisation. 我认为问题是使用可能位于美国的jsfiddle,因此目前正在使用本地化。
I did the following on my node server (based in London, UK) and the following code now works when I compare the results to worldtimebuddy.com/est-to-utc-converter : 我在节点服务器(位于英国伦敦)上执行了以下操作,现在将结果与worldtimebuddy.com/est-to-utc-converter进行比较时,以下代码现在可以工作:
var unix = moment.tz('2016-04-22T15:00', "America/New_York").unix();
var zulu = moment.utc(unix, 'X').format();
var local= new Date(zulu).toString();
console.log(unix); // 1461351600 (epochconverter.com --> Fri, 22 Apr 2016 19:00:00 GMT)
console.log(zulu); // 2016-04-22T19:00:00Z
console.log(local); // Fri Apr 22 2016 20:00:00 GMT+0100 (GMT Daylight Time)
Summary, the times are now correctly converted: 总结,现在时间已正确转换:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.