将毫秒数述转为时分秒格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function formatSecondToHHmmss(time) {
time = Number(time);
if (time < 0) time = 0;
let str = ''

const secs = Math.floor(time / 1000);
const sec = Math.floor(secs % 60);
const mins = Math.floor(secs / 60);
const min = Math.floor(mins % 60);
const hour = Math.floor(mins / 60);

str = `${fixedTwo(hour)}:${fixedTwo(min)}:${fixedTwo(sec)}`;

return str;
}
1
console.log(formatSecondToHHmmss(75000)) // 00:01:15