javascript实现网页日期和时间显示
实现效果:2014年9月3日 星期三 下午12:58:44
javascript函数代码:
function showClock()
{
d = new Date();
mt = d.getMonth() + 1;
yy = d.getYear()+1900;
weekVal = d.getDay();
if (weekVal==0) msg1="星期日"; else if (weekVal==1) msg1="星期一"; else if (weekVal==2) msg1="星期二"; else if (weekVal==3) msg1="星期三"; else if (weekVal==4) msg1="星期四"; else if (weekVal==5)msg1="星期五"; else if (weekVal==6) msg1="星期六";
dd = d.getDate();
hours = d.getHours();
minutes = d.getMinutes();
seconds = d.getSeconds();
clck = (hours>=12)?"下午":"上午";
hours = (hours>12)?hours-12:hours;
hours = (hours<10)?"0"+hours:hours;
minutes = (minutes<10)?"0"+minutes:minutes;
seconds = (seconds<10)?"0"+seconds:seconds;
time =yy+"年"+mt+"月"+dd+"日"+" "+msg1+" "+clck + " " + hours + ":" + minutes + ":" + seconds;
time = "<font size='2' face='Arial'>" + time + "</font>";
myclock.innerHTML = time;
setTimeout("showClock()",1000);
}