How to get "Yesterday/Today/Tomorrow/NextWeek" as ouput on passing date as a string in moment.js.
var date = "12/11/2015";
After passing this to moment , need output whether the date is
Yesterday
or Today
or Tomorrow
or NextWeek
.
formatDateAsDay("12/11/2015", "DD/MM/YYYY");
formatDateAsDay(date,format) {
var dayName = window.moment(new Date(date)).calendar(null, {
lastDay:'[Yesterday]',
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'ddd',
sameElse: format
});
return dayName;
}
In moment there is a calendar function that takes callback object which we can format based on our requirement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.