代码
templelate
<view class="comment-1-date">{{comment_1.put_time|formatDate('-')}}</view>
filter
filters: {
// 时间戳处理
formatDate: function(value, spe = '/') {
let time = Math.floor(((new Date()).valueOf() - value) / 86400000)
if (time === 0) {
let time2 = Math.round(((new Date()).valueOf() - value) / 3600000)
if (time2 > 0) {
return time2 + '小时前'
} else {
let time3=((new Date()).valueOf() - value) / 60000
if(time3>1){
return Math.ceil(time3) + '分钟前'
}else{
return Math.ceil(((new Date()).valueOf() - value)/1000)+"秒前"
}
}
} else if (time > 0 && time < 30) {
return time + '天前'
} else if (time >= 30) {
let data = new Date(value);
let year = data.getFullYear();
let month = data.getMonth() + 1;
let day = data.getDate();
let h = data.getHours();
let mm = data.getMinutes();
let s = data.getSeconds();
month = month > 10 ? month : "0" + month;
day = day > 10 ? day : "0" + day;
return `${year}${spe}${month}${spe}${day}`;
}
},
},