HTML 加载当前系统时间

  

  以下为网络收集到的 HTML 加载系统当前实时时间的HTML代码,都试试看看效果咯,笔者只是加入了一些小改动。应用时根据自己的实际情况进行更改...

   静态时间:

<!DOCTYPE html>
<html>
    <head>
        <meta content="Author" name="notfound945">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>Now Time</title>
        <script type="text/javascript">
            var myDate = new Date();
            document.write(myDate.toLocaleString())
        </script>
    </head>
        <body>
        </body>
</html>

 

  动态实时时间:

<!DOCTYPE html>
<html>
    <head>
        <meta content="Author" name="notfound945">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>Now Time</title>
        <style>
            #frame {
                height: 120px;
                width: 365px;
                margin: 200px auto -10px;
                border-radius: 25px 0 25px 0;
                background-color: #e17724
            }
            #nowdate {
                height: 100%;
                width: 380px;
                margin: -80px auto;
                font-size: 35px;
                color: white;
                text-align: center;
                box-shadow: 5px 5px #e17700;
                background-color: #d2e100;
            }
        </style>
        <script>
            function mytime(){
                var a = new Date();
                var b = a.toLocaleTimeString();
                var c = a.toLocaleDateString();
                document.getElementById("nowdate").innerHTML = c+"&nbsp"+b;
            }
            setInterval(function() {mytime()},10);
        </script>
    </head>
    <body>
    <div id="frame"></div>
        <div id="nowdate"></div>
    </body>
</html>

 

 

<!DOCTYPE html>
<html>
    <head>
        <meta content="Author" name="notfound945">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>Now Time</title>
        <style>
            #frame {
                height: 120px;
                width: 365px;
                margin: 200px auto -10px;
                border-radius: 25px 0 25px 0;
                background-color: #e17724
            }

            #nowdate {
                height: 100%;
                width: 380px;
                margin: -105px auto;
                font-size: 35px;
                color: white;
                text-align: center;
                box-shadow: 5px 5px #e17700;
                background-color: #d2e100;
            }
        </style>
        <script>
            setInterval("nowdate.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
        </script>
    </head>
        <body>
            <div id="frame"></div>
            <div id="nowdate"></div>
        </body>
</html>

 

 

<!DOCTYPE html>
<html>
    <head>
        <meta content="Author" name="notfound945">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>Now Time</title>
        <style>
            #frame {
                height: 120px;
                width: 365px;
                margin: 200px auto -10px;
                border-radius: 25px 0 25px 0;
                background-color: #e17724
            }
            #Nowtime {
                height: 100%;
                width: 380px;
                margin: -105px auto;
                font-size: 35px;
                color: white;
                text-align: center;
                box-shadow: 5px 5px #e17700;
                background-color: #d2e100;
            }
        </style>
        <script type="text/javascript">
            function show() {
                var date = new Date(); //日期对象
                var now = "此刻是";
                now = now + date.getFullYear() + "";
                now = now + (date.getMonth() + 1) + ""; //取月的时候取的是当前月-1如果想取当前月+1就可以了
                now = now + date.getDate() + "";
                now = now + date.getHours() + "";
                now = now + date.getMinutes() + "";
                now = now + date.getSeconds() + "";
                document.getElementById("Nowtime").innerHTML = now; //div的html是now这个字符串
                setTimeout("show()", 1000); //设置过1000毫秒就是1秒,调用show方法
            }
        </script>
    </head>
    <body onload="show()"> <!-- 网页加载时只需调用一次 以后就自动调用了-->
    <div id="frame"></div>
        <div id="Nowtime"></div>
    </body>
</html>

 

<!DOCTYPE html>
<html>
    <head>
        <meta content="Author" name="notfound945">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>Now Time</title>
        <style>
            #frame {
                height: 120px;
                width: 365px;
                margin: 200px auto -10px;
                border-radius: 25px 0 25px 0;
                background-color: #e17724
            }
            #nowdate {
                height: 100%;
                width: 380px;
                margin: -105px auto;
                font-size: 35px;
                color: white;
                text-align: center;
                box-shadow: 5px 5px #e17700;
                background-color: #d2e100;
            }
        </style>
        <script type="text/javascript">
            function getTime() {
                var dateObj = new Date();
                var year = dateObj.getFullYear();//
                var month = dateObj.getMonth()+1;//月  (注意:月份+1)
                var date = dateObj.getDate();//
                var day = dateObj.getDay();
                var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
                var week = weeks[day];//根据day值,获取星期数组中的星期数。
                var hours = dateObj.getHours();//小时
                var minutes = dateObj.getMinutes();//分钟
                var seconds = dateObj.getSeconds();//
                if(month<10){
                    month = "0"+month;
                }
                if(date<10){
                    date = "0"+date;
                }
                if(hours<10){
                    hours = "0"+hours;
                }
                if(minutes<10){
                    minutes = "0"+minutes;
                }
                if(seconds<10){
                    seconds = "0"+seconds;
                }
                var newDate = year+""+month+""+date+""+hours+":"+minutes+":"+seconds+"&nbsp &nbsp"+week;
                document.getElementById("nowdate").innerHTML = "此刻是" + newDate;//在div中写入时间
                setTimeout('getTime()', 500);//每隔500ms执行一次getTime()
            }
        </script>
    </head>
    <body onload="getTime()">
    <div id="frame"></div>
        <div id="nowdate"></div>
    </body>
</html>

 

 

<!DOCTYPE html>
<html>
    <head>
        <meta content="Author" name="notfound945">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>Now Time</title>
        <style>
            #frame {
                height: 120px;
                width: 365px;
                margin: 200px auto -10px;
                border-radius: 25px 0 25px 0;
                background-color: #e17724
            }
    
            #nowdate {
                height: 100%;
                width: 380px;
                margin: -105px auto;
                font-size: 35px;
                color: white;
                text-align: center;
                box-shadow: 5px 5px #e17700;
                background-color: #d2e100;
            }
        </style>
        <script>
            function fun() {
        var date = new Date();  //创建对象
                var y = date.getFullYear();     //获取年份
                var m = date.getMonth() + 1;   //获取月份  返回0-11
                var d = date.getDate(); // 获取日
                var w = date.getDay();   //获取星期几  返回0-6   (0=星期天)
                var ww = ' 星期' + '日一二三四五六'.charAt(new Date().getDay());//星期几
                var h = date.getHours();  //
                var minute = date.getMinutes()  //
                var s = date.getSeconds(); //
                var sss = date.getMilliseconds(); //毫秒
                if (m < 10) {
                    m = "0" + m;
                }
                if (d < 10) {
                    d = "0" + d;
                }
                if (h < 10) {
                    h = "0" + h;
                }
                if (minute < 10) {
                    minute = "0" + minute;
                }
                if (s < 10) {
                    s = "0" + s;
                }
                if (sss < 10) {
                    sss = "00" + sss;
                } 
         
else if (sss < 100) { sss = "0" + sss; } document.getElementById("nowdate").innerHTML = y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + s + "." + sss + " " + ww; setTimeout("fun()",1);//1 ms更新一次 } </script> </head> <body onload="fun()"> <div id="frame"></div> <div id="nowdate"></div> </body> </html>

 

转载于:https://www.cnblogs.com/notfound/articles/8448652.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值