码迷,mamicode.com
首页 > Web开发 > 详细

网页时间显示

时间:2015-01-05 09:24:46      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

简单一点的网页时间显示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>time</title>
</head>
<body>
	
</body>
</html>
<script>
    clock();
    setInterval(clock,1000);
    function clock(){
        var oDate = new Date();
        var year = oDate.getFullYear();
        var month = oDate.getMonth()+1;
        var date = oDate.getDate();
        var week = ‘星期‘+‘日一二三四五六‘.charAt(oDate.getDay());
        var hour = oDate.getHours();
        var time = oDate.getMinutes();
        var second = oDate.getSeconds();
        var str = year+‘年‘+month + ‘月‘+ date+ ‘日‘+week+ ‘‘+toTwo(hour)+‘时‘+toTwo(time)+‘分‘+toTwo(second)+‘秒‘;
        document.body.innerHTML=str;
    }

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

  

网页时间显示

标签:

原文地址:http://www.cnblogs.com/senhero/p/4202687.html

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