// 处理时间
filters: {
uptime(val) {
let oldDate = new Date(val*1000);
console.log(oldDate.toTimeString().split(' ')[0].slice(0,5));
let nowDate = new Date();
let time = nowDate.getTime();
let difference = (time - val*1000);
let h24 = 24 * 60 * 60*1000;
let h1 = 60 * 60 *1000;
let h48 = 48 * 60 * 60*1000;
let s1 = 60*1000
if (difference > h48) {
// return `${oldDate.getMonth()+1}月${oldDate.getDate()}日`;
return `${oldDate.getMonth()+1}-${oldDate.getDate()} ${oldDate.toTimeString().split(' ')[0].slice(0,5)}`;
} else if(difference > h24 && difference < h48) {
return `昨天`;
}else if(h1<difference && difference<h24){
// 大于一小时小于24小时
return `${Math.floor(difference/1000/60/60)}小时前`
}else if(difference>s1 && difference<h1){
//大于一分钟小于一小时
return Math.round((difference / (1000 * 60))) + '分钟前'
}else if(difference<s1){
//小于一分钟
return Math.round((difference / (1000))) + '秒前'
}
}
}
Vue使用过滤器对时间戳进行处理
最新推荐文章于 2023-08-11 11:22:44 发布