fix: 完成: 诊所设置中心,消息中心
This commit is contained in:
@@ -348,3 +348,28 @@ export function getRegisterStatus(status: number) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 把格式化时间转换成相对时间(刚刚,几分钟前,几小时前,几天前,几周前)
|
||||
export function formatTimeToRelative(time: string) {
|
||||
const now = new Date();
|
||||
const date = new Date(time);
|
||||
const diff = now.getTime() - date.getTime();
|
||||
const seconds = Math.floor(diff / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
const weeks = Math.floor(days / 7);
|
||||
|
||||
if(seconds < 60) {
|
||||
return '刚刚';
|
||||
} else if(minutes < 60) {
|
||||
return `${minutes} 分钟前`;
|
||||
} else if(hours < 24) {
|
||||
return `${hours} 小时前`;
|
||||
} else if(days < 7) {
|
||||
return `${days} 天前`;
|
||||
} else if (weeks < 4) {
|
||||
return `${weeks} 周前`;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user