嗯,我只是无法使用moment.js递增日期。我在我的代码中得到一个javascript日期对象,将它包装到moment
函数中,计算我需要添加到初始日期的小时数,并且在我使用.add
方法后没有任何反应。尝试做像currentTime.add(2, 'hours')
这样的工作,这并不奏效。我做错了什么?无法使用moment.js递增日期
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'的原始值是什么? – Barmar
你知道'add()'修改对象的位置,它不会返回一个新的对象,对吧? – Barmar
你必须使用['format()'](http://momentjs.com/docs/#/displaying/format/)来显示矩对象的值。请参阅[这里](https://stackoverflow.com/a/44812821/4131048)了解与控制台中打印值有关的问题。 – VincenzoC