feat: update
This commit is contained in:
@@ -14,3 +14,24 @@ dayjs.extend(timezone);
|
||||
export function formatDate(date) {
|
||||
return dayjs.tz(date, 'Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format seconds to readable duration string
|
||||
* @param {number} seconds - Number of seconds
|
||||
* @returns {string} Formatted duration string (e.g., "2h 30m 15s")
|
||||
*/
|
||||
export function formatDuration(seconds) {
|
||||
if (!seconds || seconds < 0) return '0 秒';
|
||||
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
const remainingSeconds = Math.floor(seconds % 60);
|
||||
|
||||
const parts = [];
|
||||
if (hours > 0) parts.push(`${hours} 时`);
|
||||
if (minutes > 0) parts.push(`${minutes} 分`);
|
||||
if (remainingSeconds > 0 || parts.length === 0) parts.push(`${remainingSeconds} 秒`);
|
||||
|
||||
return parts.join(' ');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user