简体   繁体   English

添加到Moment时如何调试奇怪的行为?

[英]How to debug strange behavior when adding to Moment?

So some precursor information. 所以一些前兆信息。 The date I am calculating from: 2016-04-11T22:12:36.000Z 我计算的日期: 2016-04-11T22:12:36.000Z

I add 12 hours to it by doing: 我通过以下方式添加了12个小时:

var time = new Date(d.dateCreated)
time = Number(time)
diff = parseInt(d.time) * 3600
diff = time + diff

The calculated differences of the code is: 计算出的代码差异是:

console.log(time,diff)
//result: 1460412756000 1460412799200

Then when I run the following code: 然后当我运行以下代码时:

var m = moment().diff(diff, 'hours')
//Returns 194 hours

What exactly am I doing wrong? 我究竟做错了什么?

You're not reading the documentation and utilizing it, that's what you're doing wrong. 你没有阅读文档并使用它,这就是你做错了。 Sorry to be crass... 抱歉是粗鲁......

You want to do this to your date/time 你想这样做你的日期/时间

(from the moment docs -- http://momentjs.com/docs/#/manipulating/add/ ) (从文档开始 - http://momentjs.com/docs/#/manipulating/add/

moment().add(12, 'hours');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM