Js时间刷新

网站JS时间刷新显示代码:

废话少说,先看效果:

var myDate,year,month,day,date,weeks,weekday,hour,min,sec;
function run(){
myDate = new Date();
year = myDate.getFullYear();
month = myDate.getMonth()+1;
month = month>9 ? month : "0"+month;
day = myDate.getDate();
date = year+"年"+month+"月"+day+"日";

weeks =['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
weekday = weeks[myDate.getDay()];

hour = myDate.getHours();
hour = hour>9 ? hour :"0"+hour;
min = myDate.getMinutes();
min = min>9 ? min : "0"+min;
sec = myDate.getSeconds();
sec = sec>9 ? sec : "0"+sec;
document.getElementById("time").innerHTML=date+"("+weekday+")"+hour+":"+min+":"+sec;
}
setInterval(run,1000);//浏览器刷新

html代码:现在是:<span id="time"></span>

 

posted @ 2014-05-29 15:08  风雨断肠人1991  阅读(168)  评论(0编辑  收藏  举报