Moment.js compare two date thrown a warning
我创建了一个简单的应用程序,需要进行日期比较。 我使用了Moment.js,并尝试回答以下问题:
比较JS中的两个日期
Moment JS日期时间比较
如何只比较moment.js中的日期
但是他们都不为我工作。
现在我使用此代码:
1 2 3 4 5 | if(moment('09/12/2016').isAfter('09/11/2016')){ console.log("True") } else { console.log("False") } |
但是在控制台中,它引发了警告:
Deprecation warning: moment construction falls back to js Date. This
is discouraged and will be removed in upcoming major release. Please
refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
大家请帮帮我。 这是我的小提琴https://jsfiddle.net/gq6ykw8L/
您的日期字符串在
This deprecation warning is thrown when no known format is found for a
date passed into the string constructor. To work around this issue,
specify a format for the string being passed to moment().
您需要使用
1 2 | moment('09/12/2016', 'DD/MM/YYYY'); moment('09/12/2016', 'MM/DD/YYYY'); |