Moment.js Check a date is today

后端 未结 5 1318
礼貌的吻别
礼貌的吻别 2020-12-25 10:30

How do I check a date is actually today (the same date) rather than the difference between hours in a day?

I have three timestamps as examples, one is today (22/07/1

5条回答
  •  佛祖请我去吃肉
    2020-12-25 11:05

    You can use isSame(), limiting the granularity to a day:

    var today = moment(1406019110000);
    var yesterday = moment(1405951867000);
    
    if (today.isSame(yesterday, 'd')) {
        // They are on the same day
    } else {
        // They are not on the same day
    }
    

提交回复
热议问题