export function compareTimestamp(timestamp) {
const currentTime = new Date().getTime();
const timeDiff = currentTime - timestamp;
if (timeDiff < 60000) {
return '1分钟内';
} else if (timeDiff < 3600000) {
return Math.floor(timeDiff / 60000) + '分钟';
} else if (timeDiff < 86400000) {
return Math.floor(timeDiff / 3600000) + '小时';
} else if (timeDiff < 2592000000) {
return Math.floor(timeDiff / 86400000) + '天';
} else if (timeDiff < 7776000000) {
return Math.floor(timeDiff / 2592000000) + '月';
} else {
let y=Math.floor(timeDiff / 31536000000)
return (y==0?1:y) + '年'; // 一年大约为 31536000000 毫秒
}
}
export function gotoHome() {
uni.showModal({
title: "提示",
content: "页面有误将返回首页",
showCancel: false,
success: (res) => {
if (res.confirm) {
uni.reLaunch({
url: "/pages/index/index"
});
}
}
});
}
标签:return,floor,js,时间,计算,export,timeDiff,else,Math
From: https://blog.csdn.net/a1241436267/article/details/142339631