zoukankan      html  css  js  c++  java
  • js获取当前时间&js 页面时钟

    js获取当前时间

    //获取当前时间,格式YYYY-MM-DD
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }

    js页面添加时钟

    <script type="text/javascript">
    function realSysTime(clock){
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth();
        var date = now.getDate();
        var day = now.getDay();
        var hour = now.getHours();
        var minu = now.getMinutes();
        var sec = now.getSeconds();
        month = month+1;
        var arr_week = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
        var week = arr_week[day];
        var time = year+"年"+month+"月"+date+"日"+" "+week+" "+hour+":"+minu+":"+sec;
        clock.innerHTML=time;
    }
    window.onload=function(){
        window.setInterval("realSysTime(clock)", 1000);
    }
    </script>

    <div id="clock"></div>
  • 相关阅读:
    【作业7】完成调查问卷
    用博客园第一周
    讲座观后感
    调查问卷
    第十一周·前端学习笔记--正则表达式
    调查问卷
    思维导图
    讲座心得1
    第一次作业(8.学习进度表)
    第一次作业(7.问卷调查)
  • 原文地址:https://www.cnblogs.com/nshuai/p/5845401.html
Copyright © 2011-2022 走看看