秒数转换成时分秒案例:
代码如下:
<!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 a = +prompt('请输入的秒数:')
function getTime(a){
h = parseInt(a/60/60%24)
m = parseInt(a/60%60)
s = parseInt(a%60)
h = h < 10 ? '0' + h:h
m = m < 10 ? '0' + m:m
s = s < 10 ? '0' + s:s
console.log(h,m,s)
return `${h}小时${m}分钟${s}秒`
}
let str = getTime(a)
document.write(str)
</script>
</body>
</html>
效果展示如下:
版权声明:本文为miss_copper原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。