【问题标题】:momentJs add days returns moment object instead of datemomentJs 添加天返回时刻对象而不是日期
【发布时间】:2019-01-21 18:20:08
【问题描述】:

我想在 Angular 项目中使用 momentJs 在日期中添加 7 天。

let nextRunAt = "2018-08-16T02:00:00.242Z";

let calculatedRunAt = moment(nextRunAt).add(7, 'days');

我希望在 7 天后得到日期,但我得到了时刻对象。

如下

感谢任何帮助。谢谢

【问题讨论】:

标签: javascript angular momentjs


【解决方案1】:

moment方法返回一个moment对象,你要转换成日期-

let calculatedRunAt = moment(nextRunAt, "DD-MM-YYYY").add(7, 'days').toDate();

【讨论】:

  • 谢谢您的回答。还有一种方法可以让calculatedRunAtnextRunAt 的格式相同...我已经更新了我的问题
猜你喜欢
  • 2020-05-06
  • 1970-01-01
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
  • 1970-01-01
  • 2017-07-26
  • 1970-01-01
  • 2017-06-27
相关资源
最近更新 更多