Skip to content

@pmun/utils / formatCountdown

Function: formatCountdown() ​

ts
function formatCountdown(endTimestamp, nowMs): string;

格式化倒计时,超过一天时显示总天数

Parameters ​

endTimestamp ​

number

截止时间戳(秒),0 视为无效

nowMs ​

number

当前时间戳(毫秒)

Returns ​

string

格式为 HH:mm:ss 或 N天 HH:mm:ss;已到期或无效输入返回空字符串

Example ​

ts
formatCountdown(1700003661, 1700000000000) // "01:01:01"
formatCountdown(1700090061, 1700000000000) // "1天 01:01:01"
formatCountdown(1700000000, 1700000000000) // ""