首页 > 文章列表 > js中isBefore函数如何判断

js中isBefore函数如何判断

js isBefore
308 2022-08-06

1、isBefore判断一个moment对象是否在某个时间点之前。

moment('2010-10-20').isBefore('2010-10-21'); // true

2、默认的比较单位是毫秒,但是假如我们想要限制到其他的时间单位,我们可以将其作为第二个参数传入。接受的单位和startOf支持的单位一样。

console.log(moment('2017-11-03').isBefore('2017-11-06'))
console.log(moment('2017-11-03').isBefore('2017-11-06', 'year'))
console.log(moment('2017-11-03').isBefore('2018-11-06', 'year'))

推荐操作环境:windows7系统、jquery3.2.1版本,DELL G3电脑。