Moment.js - tomorrow, today and yesterday

后端 未结 12 2095
悲哀的现实
悲哀的现实 2021-01-30 00:21

I\'d like the moment().fromNow() functionality, but when the date is close it is too precise - ex. I don\'t want it to show \'in 3 hours\' but \'today\' - so basica

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 00:54

    const date = moment(YOUR_DATE)
    return (moment().diff(date, 'days') >= 2) ? date.fromNow() : date.calendar().split(' ')[0]
    

提交回复
热议问题