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

【JSP】JSP动态显示时间

时间:2015-08-15 00:00:44      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:

 1 function showtime() {
 2     var today;
 3     var hour;
 4     var second;
 5     var minute;
 6     var year;
 7     var month;
 8     var date;
 9     var strDate;
10     today = new Date();
11     var n_day = today.getDay();
12     switch (n_day) {
13     case 0: {
14         strDate = "星期日"
15     }
16         break;
17     case 1: {
18         strDate = "星期一"
19     }
20         break;
21     case 2: {
22         strDate = "星期二"
23     }
24         break;
25     case 3: {
26         strDate = "星期三"
27     }
28         break;
29     case 4: {
30         strDate = "星期四"
31     }
32         break;
33     case 5: {
34         strDate = "星期五"
35     }
36         break;
37     case 6: {
38         strDate = "星期六"
39     }
40         break;
41     case 7: {
42         strDate = "星期日"
43     }
44         break;
45     }
46     year = today.getYear() - 100 + 2000;
47     month = today.getMonth() + 1;
48     date = today.getDate();
49     hour = today.getHours();
50     minute = today.getMinutes();
51     second = today.getSeconds();
52     if (month < 10)
53         month = "0" + month;
54     if (date < 10)
55         date = "0" + date;
56     if (hour < 10)
57         hour = "0" + hour;
58     if (minute < 10)
59         minute = "0" + minute;
60     if (second < 10)
61         second = "0" + second;
62     document.getElementById(‘clock‘).innerHTML = year + "年" + month + "月"
63             + date + "日 " + strDate + " " + hour + ":" + minute + ":" + second;
64     setTimeout("showtime();", 1000);
65 }
1 <body onLoad="showtime()">
2     <span style="float:left">
3         <span>当前时间</span>
4         <span id="clock"></span>
5     </span>
6 </body>        

技术分享

【JSP】JSP动态显示时间

标签:

原文地址:http://www.cnblogs.com/zhengbin/p/4731454.html

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