我創建了一個角度指令,只提供日期的日期。 如果你不使用角度,只需使用該功能。
app.filter('amCalendarDate', function($translate) {
return function(dt) {
var md = moment(dt), key = '';
if (!dt || !md || (md + '').toLowerCase() == 'invalid date')
return '';
var today = moment();
var diff = today.diff(md, 'days');
if (!diff)
key = 'Today';
else if (diff == -1)
key = 'Tomorrow';
else if (diff == 1)
key = 'Yesterday';
else if (Math.abs(diff) <= 6) {
if (diff < 0)
key = 'Next';
else
key = 'Last';
var days = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
today.day(diff);
key += ' ' + days[today.day()];
}
if (key) {
// if you don't have translate, just return the key
return $translate.amCalendarDate[key];
} else
return md.format('L');
}
});
與您的解決方案,我需要定義日曆應用程序的所有支持語言..:/ – Luckylooke
3年前,這將是如此 - 我不知道今天它是如何工作的!今天 –
似乎是相同的情況:/ – Luckylooke