2022年了,提前祝大家2023年快乐——2023年倒计时

效果展示:
在这里插入图片描述

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>倒计时</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html, body {
            height: 100%
        }

        body {
            background-image: url("newyear.jpg");
            background-size: 100% 100%;
            background-position: center center;
            font-size: 28px;
            font-family: "宋体";
            overflow-y: hidden;
            overflow-y: hidden;
        }

        .main {
            width: 100%;
            height: 100%;
            /*margin: 10% auto;*/
            /*border: 1px solid red;*/
        }

        .title {
            /*background: #20a53a;*/
            color: greenyellow;
            font-size: 40px;
            height: 50px;
            line-height: 50px;
            /*padding-left: 20px;*/
            text-align: center;
        }

        .content {
            /*background-color: #f3f7f9;*/
            height: calc(100% - 50px);
            border: 1px dashed #c6d9b6;
            text-align: center;
        }

        #time {
            display: block;
            margin-top: 100px;
            /*line-height: 900px;*/
            font-size: 60px;
            /*font-size: 100%;*/
            vertical-align: middle;
            color: yellow;
        }
    </style>
</head>

<body>
<div class="main">
    <div class="title">2023</div>
    <div class="content">
        <p id="time">祝大家新年快乐呀!</p>
    </div>
</div>
</body>
<script>
    window.onload = function () {
        let oTime = document.querySelector('#time')
        let Timer = setInterval(function () {
            let date = new Date()
            date.getDay()
            date.getMonth()
            date.getFullYear()
            console.log(date.getFullYear() == 2023)
            if (date.getFullYear() == 2023) {
                oTime.innerHTML = `2023,新年快乐!`
                clearInterval(Timer)//由 setInterval()返回的ID值可用作clearInterval()方法的参数。
            }
            oTime.innerHTML = ` 距 2023 年还有<br><br>
                                ${11 - date.getMonth()}${getMonthDays(date.getFullYear(), date.getMonth()) - date.getDate()}${23 - date.getHours()}${59 - date.getMinutes()}${60 - date.getSeconds()}`;
        }, 999)

        //获取某年某月天数
        function getMonthDays(year, month) {
            let date = new Date(year, month, 0)
            return date.getDate();
        }
    }
</script>
</html>

在下提前祝大家 2023 新年快乐!

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
HTML无法直接实现倒计时功能,但可以通过JavaScript结合HTML来实现。 要实现2023倒计时,首先需要计算当前时间与目标时间之间的时间差。可以使用JavaScript的Date对象来获取当前时间,然后创建一个表示目标时间的Date对象。 接下来,通过这两个时间对象的getTime()方法获取它们的时间戳。将目标时间的时间戳减去当前时间的时间戳,得到时间差。然后将时间差转换为天、小时、分钟和秒。 最后,将这些值插入到HTML文件中的特定元素中,以显示倒计时效果。 以下是一个实现2023倒计时的HTML和JavaScript示例代码: ```html <!DOCTYPE html> <html> <head> <title>2023倒计时</title> <style> #countdown { font-size: 24px; text-align: center; margin-top: 200px; } </style> </head> <body> <div id="countdown"></div> <script> // 目标时间为20231月1日 00:00:00 var targetDate = new Date("2023-01-01T00:00:00"); var countdownElement = document.getElementById("countdown"); function updateCountdown() { var currentDate = new Date(); var timeDifference = targetDate.getTime() - currentDate.getTime(); // 计算剩余的天数、小时、分钟和秒数 var days = Math.floor(timeDifference / (1000 * 60 * 60 * 24)); var hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((timeDifference % (1000 * 60)) / 1000); // 更新倒计时元素的内容 countdownElement.innerHTML = "距离2023还有:" + days + "天 " + hours + "小时 " + minutes + "分钟 " + seconds + "秒"; // 每秒更新一次倒计时 setTimeout(updateCountdown, 1000); } // 初始化倒计时 updateCountdown(); </script> </body> </html> ``` 该代码会显示一个位于页面中央的倒计时元素,每秒钟更新一次,直到达到20231月1日的目标时间为止。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心醉瑶瑾前

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值