1
This commit is contained in:
14
src/utils/format.ts
Normal file
14
src/utils/format.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 格式化秒为hh:mm:ss
|
||||
*/
|
||||
export function formatSecond(seconds: number) {
|
||||
if (seconds <= 0) return "Expired";
|
||||
|
||||
const d = Math.floor(seconds / (3600 * 24));
|
||||
const h = Math.floor((seconds % (3600 * 24)) / 3600);
|
||||
const m = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
if (d > 0) return `${d}d ${h}h`; // 大于1天显示 天+小时
|
||||
if (h > 0) return `${h}h ${m}m`; // 小于1天显示 小时+分钟
|
||||
return `<1h`; // 小于1小时显示 <1h
|
||||
}
|
||||
Reference in New Issue
Block a user