<script language="javascript">
function showTime(){
var date=new Date();
var hours=date.getHours();
var minutes=date.getMinutes();
var seconds=date.getSeconds();
if(hours.toString().length == 1){
hours='0'+hours;
}
if(minutes.toString().length == 1){
minutes='0'+minutes;
}
if(seconds.toString().length == 1){
seconds='0'+seconds;
}
var formatTime=hours+":"+minutes+":"+seconds;
setTimeout("showTime()", 1000);
/* setInterval("showTime()",1000);*/
document.getElementById("time").innerHTML=formatTime;
}
</script>原文:http://blog.csdn.net/dapeng0112/article/details/41982195