import Vue from 'vue'
|
|
Vue.filter('formatDate', (value: string): string => {
|
const date = new Date(value);
|
const today = new Date();
|
|
const isToday = (compareDate: Date): boolean => {
|
return compareDate.getFullYear() === today.getFullYear()
|
&& compareDate.getMonth() === today.getMonth()
|
&& compareDate.getDate() === today.getDate();
|
};
|
|
const isThisYear = (compareDate: Date): boolean => {
|
return compareDate.getFullYear() === today.getFullYear();
|
}
|
|
if (isThisYear(date)) {
|
return isToday(date)
|
? `今天 ${date.getHours()}:${date.getMinutes()}`
|
: `${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`;
|
} else {
|
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours()}:${date.getMinutes()}`;
|
}
|
|
})
|