I need to format some days in the format "Yesterday 17th May 2015" using moment.js. This is what I have so far:
var asd = moment(moment.utc("2015-09-30T08:35:40.59")) .subtract(1, 'days') .calendar();
As described in the Calendar customization doc is it possibile to customize the format of calendar.
In the example below, I customized the sameElse format of calendar for the English locale to return a string with the format you required:
sameElse
calendar
moment.locale('en', { calendar : { sameElse : '[Yesterday] Do MMM YYYY' } }); var asd = moment.utc("2015-09-30T08:35:40.59") .subtract(1, 'days') .calendar(); console.log(asd);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script>
As described in the Calendar customization doc is it possibile to customize the format of calendar.
In the example below, I customized the
sameElseformat ofcalendarfor the English locale to return a string with the format you required: