JavaScript—当前时间

当前时间-倒计时下载

效果:

代码:

复制代码
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>倒计时js代码</title>
    <style>
        *
        {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        body
        {
            font-size: 18px;
            text-align: center;
        }
        .time
        {
            height: 30px;
            padding: 200px;
        }
    </style>
</head>
<body>
    </div>
    <!--当前时间-->
    <div id="show">
    </div>
</body>

<script>//当前时间
    window.onload = function() {
        var show = document.getElementById("show");
        setInterval(function() {
            var time = new Date();
            // 程序计时的月从0开始取值后+1
            var m = time.getMonth() + 1;
            var t = time.getFullYear() + "-" + m + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
            show.innerHTML = t;
        }, 1000);
    };
</script>

</html>
复制代码

 

动态显示当前时间,带日期

效果:

代码:

复制代码
//动态显示当前的时间
    function GetTime(obj) {
        var myDate = new Date();
        var Today = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        //获取当前年
        var Years = myDate.getFullYear();
        //获取当前月
        var Months = myDate.getMonth() + 1;
        //获取当前日
        var Dates = myDate.getDate();

        //获取当前天是当前周的第几天
        var Days = Today[myDate.getDay()];

        //获取当前的时
        var Hours = myDate.getHours();
        //获取当前的分
        var Minutes = myDate.getMinutes();
        //获取当前的秒
        var Seconds = myDate.getSeconds();

        Months = Months < 10 ? "0" + Months : Months;
        Dates = Dates < 10 ? "0" + Dates : Dates;

        Hours = Hours < 10 ? "0" + Hours : Hours;
        Minutes = Minutes < 10 ? "0" + Minutes : Minutes;
        Seconds = Seconds < 10 ? "0" + Seconds : Seconds;

        return Years + "年" + Months + "月" + Dates + "日" + " " + Days + " " + Hours + ":" + Minutes + ":" + Seconds;
    }

    function showTitleInfo() {
        document.getElementById("dateInfo").innerHTML = GetTime();
        setTimeout("showTitleInfo()", 1000);
    }
    showTitleInfo();
复制代码

 

posted @     阅读(623)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示