How to compare only date in moment.js

后端 未结 5 2064
余生分开走
余生分开走 2020-12-08 03:38

I am new to moment.js. I have a date object and it has some time associated with it. I just want to check if that date is greater than or equal to today\'s date,

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 04:22

    For checking one date is after another by using isAfter() method.

    moment('2020-01-20').isAfter('2020-01-21'); // false
    moment('2020-01-20').isAfter('2020-01-19'); // true
    

    For checking one date is before another by using isBefore() method.

    moment('2020-01-20').isBefore('2020-01-21'); // true
    moment('2020-01-20').isBefore('2020-01-19'); // false
    

    For checking one date is same as another by using isSame() method.

    moment('2020-01-20').isSame('2020-01-21'); // false
    moment('2020-01-20').isSame('2020-01-20'); // true
    

提交回复
热议问题