Disini akan dibahas bagaimana cara menampilkan waktu dengan javascript. Waktu yang ditampilkan adalah waktu PC yang digunakan, bukan waktu server, karena sifat dari javascript adalah client side.
Berikut adalah contoh sederhana untuk menampilkan waktu:
<script language=”JavaScript”>
<!–
var clockID = 0;
function UpdateClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
var tDate = new Date();
document.theClock.theTime.value = “”
+ tDate.getHours() + “:”
+ tDate.getMinutes() + “:”
+ tDate.getSeconds();
clockID = setTimeout(“UpdateClock()”, 1000);
}
function StartClock() {
clockID = setTimeout(“UpdateClock()”, 500);
}
function KillClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
}
//–>
</script>
<body onload=”StartClock()” onunload=”KillClock()”>
<center><form name=”theClock”>
<input type=”text” name=”theTime” size=”8″ style=”font-family: Tahoma; font-size: 10px; font-weight: bold; border: 1px solid #FFFFFF”>
<form></center>
Source: sitelevelsearch.com
Suwon Bang Sofiudin atas infonya tak coba dulu script2 ya
Nem : Yusuf Abd