Moment.js isBefore函数无法按预期运行 [英] Moment.js isBefore function not working as expected
问题描述
我的控制台日志给了我意外的输出.
My console log is giving me an unexpected output.
var bool = (moment("2017-04-08 23:00:00").isBefore(moment("2017-04-09 01:00:00", 'day')));
console.log(bool);
由于某种原因,输出为false. 根据文档,以下代码应返回true.
The output is false, for some reason. According to the documentation, the following code should return true.
moment('2010-10-20').isBefore('2011-01-01', 'year')
即使不是整整一年,如果是不同的年份,我的理解是它应该返回false. 就我而言,虽然还没有24小时,但那是另一天. 有什么我不能正确理解的东西吗?
Even if it's not a full year past, if it's a different year, my understanding is that it should return false. In my case, while it hasn't yet been 24 hours, it is a different day. Is there something I'm not understanding correctly?
推荐答案
@Oliver Charlesworth 是正确的,moment()
不接受'day'
作为第二个参数.在此处进行浏览,并向下滚动以获取其所有有效签名.
@Oliver Charlesworth is right, moment()
doesn't accept 'day'
as a second argument. Have a look here and scroll down for all its valid signatures.
话虽如此,您可以转换
isBefore(moment("2017-04-09 01:00:00", 'day'));
到
isBefore(moment('2017-04-09 01:00:00'), 'day');
或
isBefore('2017-04-09 01:00:00', 'day')
;
两个工作.
此处是isBefore的签名.
Here is the signature for isBefore.
这篇关于Moment.js isBefore函数无法按预期运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!