首页 > 编程语言 > 详细

JavaScript - 获取系统当前时间

时间:2015-04-25 18:28:14      阅读:226      评论:0      收藏:0      [点我收藏+]

获取系统当前时间

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>test08.html</title>
    <script type="text/javascript">
        function showTime(){
            var today=new Date();
            var year=today.getFullYear();
            var month=today.getMonth()+1;
            var date=today.getDate();
            var hour=today.getHours();
            hour=checkTime(hour);
            var shangxia="上午";
            if(hour>12){
                shangxia="下午";
                hour=hour-12;
            }
            var minute=today.getMinutes();
            minute=checkTime(minute);
            var second=today.getSeconds();
            second=checkTime(second);
            var day=today.getDay();
            var weekday;
            switch(day){
                case 0:
                    weekday="星期天";
                    break;
                case 1:
                    weekday="星期一";
                    break;
                case 2:
                    weekday="星期二";
                    break;
                case 3:
                    weekday="星期三";
                    break;
            }
            var currentTime=year+"年"+month+"月"+date+"日 "+hour+":"+minute+":"+second+" "+shangxia+" "+weekday;
            document.getElementById("time").innerHTML=currentTime;  
        }

        function checkTime(t){
            if(t<10){
                t="0"+t;
            }
            return t;
        }

        setInterval("showTime()",1000);
    </script>
  </head>

  <body>
    <div id="time"></div>
  </body>
</html>

JavaScript - 获取系统当前时间

原文:http://blog.csdn.net/wangzi11322/article/details/45270711

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!