【问题标题】:Moment JS: Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release [duplicate]Moment JS:弃用警告:moment 构造回退到 js 日期。这是不鼓励的,将在即将发布的主要版本中删除[重复]
【发布时间】:2015-03-01 11:17:56
【问题描述】:

我收到Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info. 但我是一个新手,我不知道如何解决它,所以上面的消息消失了。 我认为问题在于这两行,但我不确定。

var nextMonth = moment(moment(year + "-" + month + "-1")).add(1, "months").format("MM");
var nextYear  = moment(moment(year + "-" + month + "-1")).add(1, "months").format("YYYY");

我已经检查了https://github.com/moment/moment/issues/1407Deprecation warning: moment construction falls back to js Date,但似乎都无法解决我的问题。

我想知道在这个计算中我应该在哪里告诉当前的格式,或者至少如何以正确的格式进行这个计算,这样警告就会消失。

提前致谢!

【问题讨论】:

标签: javascript node.js momentjs


【解决方案1】:

其实我发现了问题。

只需将 new Date() 添加到两个计算中,它就会再次标准化。

var nextMonth = moment(new Date(year, month - 1, 1)).add(1, "months").format("MM");
var nextYear  = moment(new Date(year, month - 1, 1)).add(1, "months").format("YYYY");

希望对其他人有所帮助!

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-11-26
  • 2016-09-17
  • 1970-01-01
  • 1970-01-01
  • 2019-07-30
  • 2020-05-27
  • 2018-02-10
  • 1970-01-01
相关资源
最近更新 更多