Moment.js - tomorrow, today and yesterday

后端 未结 12 2093
悲哀的现实
悲哀的现实 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 01:14

    Here is how I do that using moment:

      let today = moment().format('DD MMMM YYYY');
    
      let tomorrow = moment().add(1, 'days').format('DD MMMM YYYY').toString();
    
      let yesterday = moment().subtract(1, 'days').startOf('day').format('DD MMMM YYYY').toString();
    
    

提交回复
热议问题