查看结果在控制台查看,按F12键----Console
<!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>
<!-- 8. 场景题:编写程序计算今天还剩多少小时,多少分钟,多少秒。将计算结果打印到控制台。(考点:日期对象、逻辑思维) -->
<script>
// 获取系统当前时间
let date = new Date();
// 第二天的零点(要想使用正确的倒计时,请修改时间)
let date2 = new Date("2023/03/16 00:00:00")
// 获取时间戳,并从毫秒数转换为秒数
let time = (date2.getTime() - date.getTime()) / 1000;
let h = Math.floor(time / 3600);
let m = Math.floor(time / 60 % 60);
let s = Math.floor(time % 60);
console.log(`今天还剩${h}时${m}分${s}秒`);
</script>
</body>
</html>
想要其他的倒计时,请在评论区Q哦!