獲取機器上的時間

 1    //計時器
 2 var spans =document.getElementsByTagName("span");
 3 var time=null;
 4 function checkTime(i){
 5     if(i<10){
 6         i="0"+i;
 7         return i;
 8     }
 9     else{
10         return i;
11     }
12 }
13 timer=setInterval(function(){
14     var now=new Date();
15     y=now.getYear();
16     mo=now.getMonth();
17 
18     h=now.getHours();
19     m=now.getMinutes();
20     s=now.getSeconds();
21     s=checkTime(s);
22     spans[0].innerHTML=h+"小時--" +m+"分鐘--" + s+"秒--" + y +"年--"+mo+"月 .l";
23 },500);
相關文章
相關標籤/搜索