Skip to content

formatSeconds

formatSeconds(seconds?, format?): string

格式化秒数为时分秒

将秒数转换为 HH:MM:SS 格式的时间字符串

Parameters

NameTypeDefault valueDescription
secondsnumber0要格式化的秒数
formatstring'HH:mm:ss'-

Returns

string

格式化后的时间字符串

Example

ts
formatSeconds(3661); // 返回 "01:01:01"
formatSeconds(70);   // 返回 "00:01:10"
formatSeconds(0);    // 返回 "00:00:00"

Released under the MIT License.