界面显示时间

 1 <html>
 2 <body>
 3 <script type="text/javascript">
 4 function showTime() {
 5     "use strict"
 6     var temp_CurrentTime = document.getElementById('temp_CurrentTime');
 7     if(!temp_CurrentTime){
 8         var show = document.createElement('div');
 9         show.setAttribute('id','temp_CurrentTime');
10         document.body.appendChild(show);
11         temp_CurrentTime = document.getElementById('temp_CurrentTime');
12     } 
13     var currentTime = new Date;
14     var hours =  currentTime.getHours();
15     if(hours < 10) {
16             hours = '0' + hours;    
17         }
18         var minutes = currentTime.getMinutes();
19         if(minutes < 10) {
20             minutes = '0' + minutes;    
21         }
22         var seconds = currentTime.getSeconds();
23         if(seconds < 10) {
24             seconds = '0' + seconds;    
25         }
26         temp_CurrentTime.innerHTML =     currentTime.getFullYear() + '' + (currentTime.getMonth() + 1)
27  + '' + currentTime.getDate() + '' + ' ' + hours + '' + minutes + '' + seconds;    
28      }
29     
30     window.onload = function() {
31         setInterval('showTime()',1000);    
32     }
33 </script>
34 
35 </body>
36 </html>
posted on 2012-09-04 14:41  jian_xie  阅读(256)  评论(0编辑  收藏  举报