【发布时间】:2017-08-28 14:04:02
【问题描述】:
好吧,我只是不能用 moment.js 增加日期。我在我的代码中获得了一个 javascript 日期对象,将其包装到 moment 函数中,计算我需要添加到初始日期的小时数,并且在我使用 .add 方法之后没有任何反应。尝试做类似currentTime.add(2, 'hours') 的事情,但效果不佳。我做错了什么?
const currentTime = moment(ioc.get<Main.IArchiveManager>("ArchiveManager").getCurrentDate());
const speed = this.getData().speed;
const distance = this.calcDistanceFromPrevPoint(initialPoint,prevPoint);
const timeToReachPoint = (distance / speed) * 60;
const estimatedTime = currentTime.add(timeToReachPoint, 'hours');
debugger;
return estimatedTime;
【问题讨论】:
-
是什么让你认为这是错误的?
currentTime的原始值是多少? -
你知道
add()修改了对象,它不会返回一个新对象,对吧? -
VincenzoC,谢谢,现在我看到了正确的值。这很违反直觉。
标签: javascript date momentjs