在页面找一个合适的位置添加div标签,用于显示时间

<div id="clock"><div>

自定义JavaScript函数 showTime()

<script language="javascript">
function showTime(clock){
    var now=new Date();
    var year=now.getFullYear();
    var month=now.getMonth()+1;
    var date=now.getDate();
    var day=now.getDay();
    var hour=now.getHours();
    var min=now.getMinutes();
    var sec=now.getSeconds();
    var arrWeek=new Array("星期一","星期二","星期三","星期四","星期五","星期六","星期天");
    var week=arrWeek[day];
    var time=year+"年"+month+"月"+date+"日  "+week+"  "+hour+":"+min+":"+sec;
    clock.innerHTML="当前时间:"+time;
</script>

在页面载入事件中每隔一秒调用一次showTime()函数,实时显示系统时间

windows.onload=function(){
    windows.setInterval("showTime(clock)",1000);
}

08-05 15:54