码迷,mamicode.com
首页 > 其他好文 > 详细

动态时钟

时间:2019-01-12 16:38:35      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:inter   func   str   htm   else   当前时间   div   html   星期六   

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<div id="div1"></div>
</body>
</html>
<script>
     window.onload = function(){    
        var oDiv = document.getElementById(‘div1‘);  //最后获取
        function timego(){
            var now = new Date();
            var year = now.getFullYear();
            var month = now.getMonth()+1;
            var date = now.getDate();
            var week = now.getDay();
            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            var str = ‘当前时间是:‘+ year + ‘年‘+month+‘月‘+date+‘日 ‘+toweek(week)+‘ ‘+todou(hour)+‘:‘+todou(minute)+‘:‘+todou(second);
            oDiv.innerHTML = str ;
        }
        timego();
        setInterval(timego,1000);
    }

    function toweek(n){
        if(n==0)
        {
            return ‘星期日‘;
        }
        else if(n==1)
        {
            return ‘星期一‘;
        }
        else if(n==2)
        {
            return ‘星期二‘;
        }
        else if(n==3)
        {
            return ‘星期三‘;
        }
        else if(n==4)
        {
            return ‘星期四‘;
        }
        else if(n==5)
        {
            return ‘星期五‘;
        }
        else
        {
            return ‘星期六‘;
        }
    }


    function todou(n){
        if(n<10)
        {
            return ‘0‘+n;
        }
        else
        {
            return n;
        }
    }
</script>

动态时钟

标签:inter   func   str   htm   else   当前时间   div   html   星期六   

原文地址:https://www.cnblogs.com/wjr2018/p/10260005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!