JavaScript 格式化时间为音视频时间

JavaScript About 599 words

需求

将时间总长格式化化为音频、视频中的时间,例如:01:50:39

代码

function formatSeconds(seconds) {
    let time;
    if (seconds <= 0) {
        time = '00:00'
    } else if (seconds < 60) {
        time = `00:${(seconds % 60).toString().padStart(2, '0')}`;
    } else if (seconds < 3600) {
        time = `${(seconds / 60 | 0).toString().padStart(2, '0')}:${(seconds % 60).toString().padStart(2, '0')}`;
    } else {
        time = `${(seconds / 3600 | 0).toString().padStart(2, '0')}:${(seconds % 3600 / 60 | 0).toString().padStart(2, '0')}:${(seconds % 60).toString().padStart(2, '0')}`;
    }
    return time;
}
Views: 701 · Posted: 2023-12-01

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh