範例

 

<script language="JavaScript1.2">
<!--
if (document.layers)
document.write('<ilayer id="clockmain" height=20><layer id="clock" width="100%"></layer></ilayer>');
else
document.write("<div><span id='clock'></span></div>");
var now,hours,minutes,seconds,timeValue;
function showtime(){
if (!document.layers&&!document.all) return;
now = new Date();
hours = now.getHours();
minutes = now.getMinutes();
seconds = now.getSeconds();
timeValue = (hours >= 12) ? "下午 " : "上午 ";
timeValue += ((hours > 12) ? hours - 12 : hours) + " 點";
timeValue += ((minutes < 10) ? " 0" : " ") + minutes + " 分";
timeValue += ((seconds < 10) ? " 0" : " ") + seconds + " 秒";
if (document.layers){
document.clockmain.document.clock.document.write(timeValue);
document.clockmain.document.clock.document.close();
}
else if (document.all)
clock.innerHTML = timeValue;
setTimeout("showtime()",100);
}
window.onload=showtime;
//-->
</script>