<script type="text/javascript">
function colok() {
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; //当月份小于10时,前补零
}
if (date < 10){
date = "0" + date; //当日期小于10时,前补零
}
if (hour < 10){
hour = "0" + hour; //当小时小于10时,前补零
}
if (minu < 10){
minu = "0" + minu; //当分钟小于10时,前补零
}
if (sec < 10){
sec = "0" + sec; //当秒小于10时,前补零
}
var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
"星期六");
week = arr_week[day];
var time = "";
time = year + "年" + month + "月" + date + "日 " + week + " " + hour + ":"
+ minu + ":" + sec;//拼接显示的字符串
document.getElementById("time").innerHTML = "[" + time + "]";
var timer = setTimeout("colok()", 1000);//每隔1000毫秒自动执行函数
}
</script>
</head>
<body onLoad="colok()">
<div id="time"></div>
</body>