[英]Moment.js using manipulation (add/sub) returns the wrong TZ
My issue was very similar to this thread: Moment.js diff between UTC dates and I see the bug was fixed ( 2 years ago ha https://github.com/moment/moment/issues/261 ) 我的问题与该线程非常相似: UTC日期之间的Moment.js差异 ,我发现该错误已修复(2年前ha https://github.com/moment/moment/issues/261 )
I experience a strange & similar issue when using version 2.5.1 of "moment.js" & version 0.0.2 of "moment-timezones.js" 使用“ moment.js”的2.5.1版本和“ moment-timezones.js”的0.0.2版本时,我遇到一个奇怪的类似问题。
var now = moment.tz("2014-03-20 12:00", "EST5EDT"); // date & a pre-defined TZ
console.log(now.format()); // 2014-03-20T12:00:00-04:00
Issue was found when using this order: 使用此订单时发现问题:
now.utc() // Converting to UTC
console.log(now.format()); // 2014-03-20T16:00:00+00:00
now.subtract('days', 3); // Subtract
console.log(now.format()); // 2014-03-17T16:00:00-04:00
Problem: original TZ (-04:00) was suddenly assigned after "subtract" 问题:“减”后突然分配了原始TZ(-04:00)
Bypassed the issue by first "subtract"ing "now" and then converting to UTC 通过先“减去”“现在”然后转换为UTC来绕过此问题
console.log(now.format()); // 2014-03-20T12:00:00-04:00
now.subtract('days', 3); // Subtract
console.log(now.format()); // 2014-03-17T12:00:00-04:00
now.utc() // Converting to UTC
console.log(now.format()); // 2014-03-17T16:00:00+00:00
Is this a bug or I'm using moment() in the wrong way ? 这是一个错误还是我以错误的方式使用了moment()?
这可能有效!
moment("2014-03-20 12:00").subtract('days', 3).tz("EST5EDT").format()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.