// time 时间戳
let timeDate = (time) => {
let friendlyTime,diffTime;
// 获取当前时间戳
const creatTime = parseInt(new Date().getTime() / 1000);
if(typeof time === "number"){
diffTime = creatTime - time;
}else {
diffTime = creatTime - new Date(time) / 1000;
}
if (diffTime !== '' && diffTime !== null) {
if (diffTime > 60 && diffTime < 60 * 60) {
friendlyTime = parseInt(diffTime / 60) + '分钟前'
} else if (diffTime > 60 * 60 && diffTime <= 60 * 60 * 24) {
friendlyTime = parseInt(diffTime / 60 * 60) + '小时前'
} else if (diffTime > 60 * 60 * 24 && diffTime <= 60 * 60 * 24 * 2) {
//超过1天
friendlyTime = "昨天";
} else if (diffTime > 60 * 60 * 24 * 2 && diffTime <= 60 * 60 * 24 * 3) {
friendlyTime = "前天";
} else if (diffTime > 60 * 60 * 24 * 3 && diffTime <= 60 * 60 * 24 * 7) {
friendlyTime = parseInt(diffTime / 86400) + "天前";
} else if (diffTime > 60 * 60 * 24 * 7 && diffTime <= 60 * 60 * 24 * 7 * 2) {
friendlyTime = "上周";
} else {
if(typeof time === 'number'){
let dateStr = new Date(time * 1000);
let number1 = dateStr.getMonth() + 1
return dateStr.getFullYear() + '-' + number1 + '-' + dateStr.getDate();
}else{
return time;
}
}
}
return friendlyTime
};