Calendar Format2.14.0+
moment.calendarFormat = Function
This lets you modify the tokens used by calendar.
moment.calendarFormat = function (myMoment, now) {
var diff = myMoment.diff(now, 'days', true);
var nextMonth = now.clone().add(1, 'month');
var retVal = diff < -6 ? 'sameElse' :
diff < -1 ? 'lastWeek' :
diff < 0 ? 'lastDay' :
diff < 1 ? 'sameDay' :
diff < 2 ? 'nextDay' :
diff < 7 ? 'nextWeek' :
// introduce thisMonth and nextMonth
(myMoment.month() === now.month() && myMoment.year() === now.year()) ? 'thisMonth' :
(nextMonth.month() === myMoment.month() && nextMonth.year() === myMoment.year()) ? 'nextMonth' : 'sameElse';
return retVal;
};
当前内容版权归 momentjs.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 momentjs.com .