javaScript中用户输入秒数转换为每小时每分每秒,小于十的自动前面加0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let arr = +prompt('请输入时间')
function getarr(x) {
let h = parseInt(x / 60 / 60 % 24)
let m = parseInt(x / 60 % 60)
let s = parseInt(x % 60)
h = h < 10 ? '0' + h : h
m = m < 10 ? '0' + m : m
s = s < 10 ? '0' + s : s
return `转换之后的时间为${h}小时${m}分${s}`
}
let time = getarr(arr)
console.log(time)
</script>
</body>
</html>
运行结果如下

