24 lines
692 B
TypeScript
24 lines
692 B
TypeScript
/** 格式化耗时 */
|
|
export const formatDuration = (seconds?: number): string => {
|
|
if (!seconds) return "-"
|
|
if (seconds < 60) return `${Math.round(seconds)}秒`
|
|
const minutes = Math.floor(seconds / 60)
|
|
const secs = Math.round(seconds % 60)
|
|
if (minutes < 60) return `${minutes}分${secs}秒`
|
|
const hours = Math.floor(minutes / 60)
|
|
const mins = minutes % 60
|
|
return `${hours}小时${mins}分`
|
|
}
|
|
|
|
/** 格式化时间 */
|
|
export const formatTime = (dateStr?: string | null): string => {
|
|
if (!dateStr) return "-"
|
|
const date = new Date(dateStr)
|
|
return date.toLocaleString("zh-CN", {
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
})
|
|
}
|