倒计时:可以用来倒计时假期

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 500px;
            height: 500px;
            display: flex;
            flex-direction: column;
            align-items: center;
            background-color: rgb(241, 213, 218);
        }

        .box {
            width: 100%;
            height: 50px;
            display: flex;
            justify-content: space-around;
            align-content: space-around;
        }

        .box div {
            text-align: center;
            line-height: 50px;
            width: 50px;
            height: 50px;
            background-color: rgb(200, 239, 244);
        }
    </style>
</head>

<body>
    <div class="box1">
        <h3>今天是。。</h3>
        <h1>下班倒计时</h1>
        <div class="box">
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <script>

        const h3 = document.querySelector('h3')
        const time = new Date()
        h3.innerHTML = `今天是${time.getFullYear()}年${time.getMonth() + 1}月${time.getDate()}日`
        const box = document.querySelectorAll('.box div')
        function getNow() {
            const now = +new Date()
            const last = +new Date(' 2025-7-16 12:00:00 ')
            let n = (last - now) / 1000
            let h = parseInt(n / 60 / 60 % 24)
            let m = parseInt(n / 60 % 60)
            let s = parseInt(n % 60)
            h = h < 10 ? '0' + h : h
            m = m < 10 ? '0' + m : m
            s = s < 10 ? '0' + s : s
            box[0].innerHTML = h
            box[1].innerHTML = m
            box[2].innerHTML = s
        }
        getNow()
        setInterval(getNow, 1000)

    </script>
</body>

</html>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值