momentjs get if date is this week, this month or this year

后端 未结 2 1166
面向向阳花
面向向阳花 2021-01-18 04:55

I am trying to pass random date values to moment and check if the date is this week, this month or this year but it seems there is no simple function to achive this without

2条回答
  •  暖寄归人
    2021-01-18 05:22

    You can use queries (check docs)

    moment(dateToCheck).isSame(new Date(), 'week'); //true if dates are in the same week
    moment(dateToCheck).isSame(new Date(), 'month'); //true if dates are in the same month
    moment(dateToCheck).isSame(new Date(), 'year'); //true if dates are in the same year
    

提交回复
热议问题