当前位置: 代码迷 >> JavaScript >> JavaScript兑现页面实时显示当前时间
  详细解决方案

JavaScript兑现页面实时显示当前时间

热度:108   发布时间:2012-11-04 10:42:41.0
JavaScript实现页面实时显示当前时间
<html>
<body>
<script language="javascript">
function showtime()
{
var today,hour,second,minute,year,month,date;
var strDate ;
   today=new Date();
var n_day = today.getDay();
switch (n_day)
{
case 0:{
strDate = "星期日"
}break;
case 1:{
strDate = "星期一"
}break;
case 2:{
strDate ="星期二"
}break;
case 3:{
strDate =  "星期三"
}break;
case 4:{
strDate =  "星期四"
}break;
case 5:{
strDate =  "星期五"
}break;
case 6:{
strDate =  "星期六"
}break;
case 7:{
strDate =  "星期日"
}break;
}
year = today.getYear();
month = today.getMonth()+1;
date = today.getDate();
hour = today.getHours();
minute =today.getMinutes();
second = today.getSeconds();
document.getElementById('time').innerHTML = year + " 年 " + month + " 月 " + date + " 日 " +  strDate +" " + hour + ":" + minute + ":" + second; //显示时间
setTimeout("showtime();", 1000); //设定函数自动执行时间为 1000 ms(1 s)
}
</script>

<div id="time"></div>

<script language="javascript"> showtime();</script>

</body>
</html>


1 楼 半边云 2010-09-02  
2 楼 zjutsoft 2010-09-02  
怎么了!!!!
  相关解决方案