uniapp/utils/common.js

23 lines
747 B
JavaScript
Raw Permalink Normal View History

2024-09-21 23:48:04 +08:00
export function getTimeDifference(timestamp) {
const now = Date.now();
const diffInSeconds = (now - timestamp) / 1000;
if (diffInSeconds < 60) {
return '1分钟';
} else if (diffInSeconds < 3600) {
const minutes = Math.floor(diffInSeconds / 60);
return `${minutes}分钟`;
} else if (diffInSeconds < 86400) {
const hours = Math.floor(diffInSeconds / 3600);
return `${hours}小时`;
} else if (diffInSeconds < 2592000) {
const days = Math.floor(diffInSeconds / 86400);
return `${days}`;
} else if (diffInSeconds < 7776000) {
const months = Math.floor(diffInSeconds / 2592000);
return `${months}`;
} else {
return `3月`;
}
}