👔 完成历史记录功能优化多语言

This commit is contained in:
7836246
2024-03-03 07:17:26 +08:00
parent f9693bd560
commit 0ea2d2a3df
12 changed files with 257 additions and 16 deletions
+28
View File
@@ -0,0 +1,28 @@
export const formatTimeAgo = (dateString: string) => {
const now = new Date();
const date = new Date(dateString);
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
let interval = seconds / 31536000;
if (interval > 1) {
return Math.floor(interval) + " 年前";
}
interval = seconds / 2592000;
if (interval > 1) {
return Math.floor(interval) + " 月前";
}
interval = seconds / 86400;
if (interval > 1) {
return Math.floor(interval) + " 天前";
}
interval = seconds / 3600;
if (interval > 1) {
return Math.floor(interval) + " 小时前";
}
interval = seconds / 60;
if (interval > 1) {
return Math.floor(interval) + " 分钟前";
}
return Math.floor(seconds) + " 秒前";
};