JS毫秒转时分秒

function formatDuring(time) {
    let days = parseInt(time / (1000 * 60 * 60 * 24));
        let hours = parseInt(time % (1000 * 60 * 60 * 24) / (1000 * 60 * 60));
        let minutes = parseInt(time % (1000 * 60 * 60) / (1000 * 60));
        let seconds = time % (1000 * 60) / 1000;
        // 格式 00天 00时 00分 00秒
        if (days < 10) { 
            days = '0' + days
        }
        if (hours < 10) {
            hours = '0' + hours
        }
        if (minutes < 10) {
            minutes = '0' + minutes
        }
        if (seconds < 10) {
            seconds = '0' + seconds
        }
        return days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
}

你可能感兴趣的:(JS常用方法)