How can I get Moment.js to return "Today" or other relevant terms? I cannot find anything in the docs that cover this.
let today = moment(); let tomorrow = moment(). add(1,'days'); let yesterday = moment(). add(-1, 'days');
Just like this: moment(). subtract(1, 'days') . It will give you the previous day with the same exact current time that is on your local pc. Save this answer.
The moment(). weekday() method is used to get or set the weekday of the Moment object. It is locale aware hence the value can depend based on whether the first day of the week is a Sunday or Monday.
I hope this will help you.
moment('2013-02-04T10:35:24-08:00').fromNow(); // '3 years ago'
moment().subtract('days', 0).fromNow(); // 'a few seconds ago'
moment().subtract('days', 1).fromNow(); // 'a day ago'
moment().subtract('days', 7).fromNow(); // '7 days ago'
You can also use calendar function:
moment().calendar(moment().add(1, 'day')); // "Yesterday at 9:14 PM"
http://momentjs.com/docs/#/displaying/calendar-time/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With