越简单越好!

javascript 动态显示时间

bevin 发表于 2006-11-28 11:14 | 4次阅读 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>

+0
发表评论
×您的大名会显示在评论处

评论内容不能少于5个字哦~~~

评论列表
当前暂无评论
发送数据中... 请求错误. 请输入评论内容和验证码后再发布 您已经参与过了,谢谢
返回顶部 ^