Comparing today's date with another date in moment is returning the wrong date, why?

后端 未结 2 1992
滥情空心
滥情空心 2021-02-05 03:06

I\'m using moment.js 1.7.0 to try and compare today\'s date with another date but the diff function is saying they are 1 day apart for some reason.

2条回答
  •  一整个雨季
    2021-02-05 03:43

    RobG's answer is correct for the question, so this answer is just for those searching how to compare dates in momentjs.

    I attempted to use startOf('day') like mentioned above:

    var compare = moment(dateA).startOf('day') === moment(dateB).startOf('day');
    

    This did not work for me.

    I had to use isSame:

    var compare = moment(dateA).isSame(dateB, 'day');
    

提交回复
热议问题