How to compare only date in moment.js

后端 未结 5 2131
余生分开走
余生分开走 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 03:57

    The docs are pretty clear that you pass in a second parameter to specify granularity.

    If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.

    moment('2010-10-20').isAfter('2010-01-01', 'year'); // false
    moment('2010-10-20').isAfter('2009-12-31', 'year'); // true
    

    As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.

    For your case you would pass 'day' as the second parameter.

提交回复
热议问题