计算今天还剩多少时、分、秒

查看结果在控制台查看,按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哦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值