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

web页面显示当前系统时间并定时刷新

时间:2016-09-09 20:50:09      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

 1 function showCurrentDate(){
 2     var today,hour,second,minute,year,month,date;
 3     var strDate ;
 4     today=new Date();
 5     var n_day = today.getDay();
 6     switch (n_day)
 7     {
 8         case 0:{
 9           strDate = "星期日"
10         }break;
11         case 1:{
12           strDate = "星期一"
13         }break;
14         case 2:{
15           strDate ="星期二"
16         }break;
17         case 3:{
18           strDate = "星期三"
19         }break;
20         case 4:{
21           strDate = "星期四"
22         }break;
23         case 5:{
24           strDate = "星期五"
25         }break;
26         case 6:{
27           strDate = "星期六"
28         }break;
29         case 7:{
30           strDate = "星期日"
31         }break;
32     }
33     year = today.getYear()+1900;
34     month = today.getMonth()+1;
35     if(month<10){
36         month="0"+month;
37     }
38     date = today.getDate();
39     if(date<10){
40         date="0"+date;
41     }
42     hour = today.getHours();
43     if(hour<10){
44         hour="0"+hour;
45     }
46     minute =today.getMinutes();
47     if(minute<10){
48         minute="0"+minute;
49     }
50     second = today.getSeconds();
51     if(second<10){
52         second="0"+second;
53     }
54     document.getElementById(‘currentDate‘).innerHTML = year + ":" + month + ":" + date + " " + strDate +" " + hour + ":" + minute + ":" + second; //显示时间
55     window.setTimeout(‘showCurrentDate()‘,1000);
56 }

 

web页面显示当前系统时间并定时刷新

标签:

原文地址:http://www.cnblogs.com/shuo1208/p/5857848.html

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