js顯示當前系統時間
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>系統時間</title>
<script language="javascript" type="text/javascript">
<!--
//獲得當前時間,刻度為一千分一秒
var initializationTime=(new Date()).getTime();
//alert(new Date());
//alert(getTime);
//alert(initializationTime);
function showLeftTime()
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var day=now.getDate();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
document.all.show.innerHTML=""+year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+"";
//一秒刷新一次顯示時間
var timeID=setTimeout(showLeftTime,1000);
}
//-->
function clockon(bgclock)
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var date=now.getDate();
var day=now.getDay();
var hour=now.getHours();
var minu=now.getMinutes();
var sec=now.getSeconds();
var week;
month=month+1;
if(month<10) month="0"+month;
if(date<10) date="0"+date;
if(hour<10) hour="0"+hour;
if(minu<10) minu="0"+minu;
if(sec<10) sec="0"+sec;
/* var arr_week=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
week=arr_week[day];
*/
switch (day){
case 1:
week="星期一";
break;
case 2:
week="星期二";
break;
case 3:
week="星期三";
break;
case 4:
week="星期四";
break;
case 5:
week="星期五";
break;
case 6:
week="星期六";
break;
default:
week="星期日"
break;
}
var time="";
time=year+"年"+month+"月"+date+"日 "+week+" "+hour+":"+minu+":"+sec;
//document.all.bgclock.innerHTML="系統公告:["+time+"]";
if(document.all)
{
bgclock.innerHTML="系統公告:["+time+"]"
}
var timer=setTimeout("clockon(bgclock)",200);
}
</script>
</head>
<!--<body onLoad="showLeftTime()" onLoad="clockon(bgclock)">-->
<body onLoad="clockon(bgclock)">
<label id="show" onClick="showLeftTime()">顯示時間的位置</label><br>
<div id="bgclock"></div>
</body>
</html>