Day12综合案例--封装计算时间函数

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>综合案例</title>
</head>

<body>
  <script>
    // 1.用户输入总秒数
    let scond = +prompt(`请输入总秒数:`)
    // 2.封装函数
    function getTime(t) {
      h = parseInt(t / 60 / 60 % 24)
      m = parseInt(t / 60 % 60)
      s = parseInt(t % 60)
      // console.log(h, m, s) 
      h < 10 ? '0' + h : h
      m < 10 ? '0' + m : m
      s < 10 ? '0' + s : s
      return `转换完毕之后是${h}小时${m}分${s}秒`
    }
    let re = getTime(scond)
    document.write(re)
  </script>
</body>

</html>
posted @ 2026-01-13 11:13  冰涿  阅读(2)  评论(0)    收藏  举报