越简单越好!

javascript 动态显示时间

发表于 2006-11-28 11:14 | 1194次阅读 0次点赞   JavaScript
<SCRIPT language=javascript> 
function checkTime(m){
 if(m<10){
  m="0"+m;
 }
 return(m);
}
function displayTime(){ 
 var now = new Date(); 
 var yy = now.getYear(); 
 var mm = now.getMonth()+1;
 //alert(mm.length);
 mm = checkTime(mm);
 var date = now.getDate();
 date = checkTime(date);
 var day = new Array(); 
 day[0] = "星期日"; 
 day[1] = "星期一"; 
 day[2] = "星期二"; 
 day[3] = "星期三"; 
 day[4] = "星期四"; 
 day[5] = "星期五"; 
 day[6] = "星期六"; 
 var days = day[now.getDay()];
 var hh = now.getHours(); 
 hh = checkTime(hh);
 var mi = now.getMinutes(); 
 mi = checkTime(mi);
 var ss = now.getTime() % 60000; 
 ss = (ss - (ss % 1000)) / 1000;
 ss = checkTime(ss);
 var all = yy+"年"+mm+"月"+date+"日 "+days+" "+hh+":"+mi+":"+ss;
 document.getElementById("gettime").innerText=all;
 //return(all);
 setTimeout('displayTime();',1000); 
} 
</SCRIPT>
<TABLE>
<TR>
 <TD id="gettime"><SCRIPT LANGUAGE="JavaScript">document.getElementById("gettime").onload=displayTime();</SCRIPT></TD>
</TR>
</TABLE>

返回顶部 ^