写在<body>区域中:
<form name="timeform">
<input type="text" size="8" name="time" style="Z-INDEX: 108; LEFT: 352px; POSITION: absolute; TOP: 16px">
</form>
<script language="JavaScript">
<!--
function showtime()
{var time=new Date();
var hour=time.getHours();
var minute=time.getMinutes();
if(minute<10)minute="0"+minute;
var second=time.getSeconds();
if(second<10)second="0"+second;
document.timeform.time.value=hour+":"+minute+":"+second;
setTimeout("showtime()","1000");
}
showtime();
// -->
</script>
<input type="text" size="8" name="time" style="Z-INDEX: 108; LEFT: 352px; POSITION: absolute; TOP: 16px">
</form>
<script language="JavaScript">
<!--
function showtime()
{var time=new Date();
var hour=time.getHours();
var minute=time.getMinutes();
if(minute<10)minute="0"+minute;
var second=time.getSeconds();
if(second<10)second="0"+second;
document.timeform.time.value=hour+":"+minute+":"+second;
setTimeout("showtime()","1000");
}
showtime();
// -->
</script>
结果会在页面中有一TextBox,时间时刻更新!
补充:上面有了取小时、分、秒的函数。
getDay() 星期几,从0-6 周日到周六的
getYear() 年,getMonth() 月, getDate() 日