How to do a greater than or equal to with moments (moment.js) in javascript?

后端 未结 3 579
忘了有多久
忘了有多久 2021-02-01 00:16

Basically, I want to do a myMoment >= yourMoment. There is no myMoment.isSameOrAfter and writing that out combining isSame and .i

相关标签:
3条回答
  • 2021-02-01 00:52

    You can use the isSameOrAfter method in momentjs:

    moment1.isSameOrAfter(moment2);
    
    0 讨论(0)
  • 2021-02-01 00:57

    Okay, I just went with the moment.js .diff() function.

    myMoment.diff(yourMoment) >= 0

    Close enough.

    0 讨论(0)
  • 2021-02-01 01:03
    let A = moment('2020-01-02');
    let B = moment('2020-01-01');
    let C = moment('2020-01-03');
    console.log(A.diff(B, 'days'));// => 1
    console.log(A.diff(C, 'days'));// => -1
    

    The supported measurements are years, months, weeks, days, hours, minutes, and seconds momentjs.com

    0 讨论(0)
提交回复
热议问题