毫秒转成时分秒/padStart实际应用

let mss = 900000;
// padStart不足两位数向前补齐
let hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString().padStart(2, '0');
let min = Math.trunc((mss % (1000 * 60 * 60)) / 60000).toString().padStart(2, '0');
let second = Math.trunc((mss % (1000 * 60)) / 1000).toString().padStart(2, '0');
console.log(`${hours}${min}${second}`);

你可能感兴趣的:(前端,javascript,开发语言)