import moment from 'moment'
moment.locale('zh-cn', {
weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'),
weekdaysShort: '周日_周一_周二_周三_周四_周五_周六'.split('_'),
calendar: {
sameDay: "[今天]MM-DD",
nextDay: "[明天]MM-DD",
lastDay: "MM-DD",
// lastDay: "[昨天]MM-DD",
nextWeek: function () {
return "MM-DD"
},
lastWeek: function () {
return "MM-DD"
},
sameElse: (date) => {
return "MM-DD"
}
}
})
const fmomentdate = (d) => {
if (!d) {
return ''
}
var td = new Date();
td = new Date(td.getFullYear(),td.getMonth(),td.getDate());
var od =new Date(d);
od = new Date(od.getFullYear(),od.getMonth(),od.getDate());
var xc = (od - td) / 1000 / 60 / 60 / 24;
return {
year: moment(d).format('YYYY年MM月DD日'),
day: moment(d).format('ddd'),
time: moment(d).format('HH:mm')
}
}
const backdate = (d) => {
if (!d) {
return ''
}
var td = new Date();
td = new Date(td.getFullYear(),td.getMonth(),td.getDate());
var od =new Date(d);
od = new Date(od.getFullYear(),od.getMonth(),od.getDate());
var xc = (od - td)/1000/60/60/24;
if (xc == 0) {
return {
name: '今天',
date: moment(d).format('MM-DD')
}
} else if (xc == 1) {
return {
name: '明天',
date: moment(d).format('MM-DD')
}
} else if (xc == 2) {
return {
name: '后天',
date: moment(d).format('MM-DD')
}
} else {
return {
name: moment(d).format('ddd'),
date: moment(d).format('MM-DD')
}
}
}