<!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 second = +prompt('请输入秒数:')
// 封装函数
function getTime(t){
let h = parseInt(t / 60 / 60 % 24)
let m = parseInt(t / 60 % 60)
let s = parseInt(t % 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(second)
document.write(str)
</script>
</body>
</html>
12_封装计算时间案例
最新推荐文章于 2024-06-20 20:20:21 发布