JS 将毫秒差值转换为时间

337 阅读1分钟

JS 将毫秒差值转换为时间

这里返回的是数组形式 [小时,分钟,秒,毫秒];

可以根据自己的需要选择是否要去掉毫秒之类的。

function funGetDiffTime(time){
    const MM = ('00'+time%1000).slice(-3)
    const S = ('0'+parseInt(time/1000%60)).slice(-2)
    const M = ('0'+parseInt(time/1000/60)%60).slice(-2)
    const H = ('0'+parseInt(time/1000/60/60)%60).slice(-2)
    return [H,M,S,MM]
}