可以写一个公共方法,直接引用即可
{{ defferDay(item?.updateTime) }}未更新
export const defferDay = (data: any) => {
if (data) {
// 将时间戳转换为毫秒
let a = new Date(data)
const startMs = a.getTime()
const endMs: any = new Date().getTime()
// 计算时间差
const timeDiff = endMs - startMs
// 将时间差转换为小时、分钟和秒
const day = Math.floor(timeDiff / (1000 * 60 * 60 * 24))
const hours = Math.floor(timeDiff / (1000 * 60 * 60))
// const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60))
// const seconds = Math.floor((timeDiff % (1000 * 60 * 60)) % (1000 * 60))
if (day <= 0) {
return hours + '小时'
} else {
return day + '天'
}
}
}