Code to show clock on the page.

Virendradugar
Posted by Virendradugar under JavaScript category on | Views : 3766
This is a java script function which will display the clock on the screen. Place a label on the screen.

<SCRIPT LANGUAGE="JavaScript">
<!--
var timerID = null;

function showtime(){
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeValue = "" + ((hours >12) ? hours -12 :hours);
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
timeValue += (hours >= 12) ? " PM" : " AM";
lblTime.innerText = timeValue;
timerID = setTimeout("showtime()",1000);
}
// -->
</SCRIPT>


Call this function on body onload event.

Comments or Responses

Login to post response