转换输入的秒数,转换为时、分、秒
/*
小时: h = parseInt(总秒数 / 60 / 60 % 24)
分钟: m = parseInt(总秒数 / 60 % 60 )
秒数: s = parseInt(总秒数 % 60)
*/
// 用户输入的秒数 转换为时分秒 不足两位补0
let times = +prompt('请您输入秒数')
function getTime(time) {
let h = parseInt(time / 60 / 60 % 24)
let m = parseInt(time / 60 % 60)
let s = parseInt(time % 60)
// 补0的操作 ctrl+d 快速选中相同的内容
h = h < 10 ? '0' + h : String(h)
m = m < 10 ? '0' + m : String(m)
s = s < 10 ? '0' + s : String(s)
// s = s < 10 ? '0' + s : s.toString()
// 不做任何处理 直接返回三个值
return [h, m, s]
}
let res = getTime(times)
console.log(res);
document.write(`您输入的秒数为${time},转换的时间为:${res[0]}:${res[1]}:${res[2]}`)