一,前端根据后端传递的时间参数对参数做过滤校验转为符合的时间格式
isSameWeek: function (inDate) {
var inDateStr = inDate.toLocaleDateString();
var nowDate = new Date();
var nowTime = nowDate.getTime();
var nowDay = nowDate.getDay();
for (var i = 0; i < 7; i++) {
if (
inDateStr ==
new Date(nowTime + (i - nowDay) * 24 * 3600 * 1000).toLocaleDateString()
) {
return true;
}
}
return false;
},
isSameYear: function (inDate) {
var nowDate = new Date();
return nowDate.getFullYear() == inDate.getFullYear();
},
getTime: function (time) {
const datatime = time.replace(/\-/g, "/");
var mytime = new Date(datatime);
var today = new Date().getTime();
var d = new Date(datatime).getTime();
console.log("今天的", today);
console.log("d");
if (mytime.toDateString() === new Date().toDateString()) {
return "今日";
}
var myDate = new Date(Date.parse(datatime));
if (this.isSameWeek(mytime)) {
return weekDay[myDate.getDay()];
}
var year = mytime.getFullYear();
var month = mytime.getMonth() + 1;
var day = mytime.getDate();
if (this.isSameYear(mytime)) {
return month + "月" + day + "日";
}
return year + "年" + month + "月" + day + "日";
},
console.log("时间---周", this.getTime("2022-05-31 15:05:42"));