Show Clock using JavaScript

 
Following program can be used to show digital clock with day on webpage like:

<html>
<head>
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
var timerID = null;
var timerRunning = false;
function stopclock ()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
 
function showtime () 
{
 var dayName = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
 var monName = new Array ("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec")
 
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
//document.clock.face.value = timeValue;
document.getElementById("timeDisplay").innerHTML="&nbsp;<b>" + dayName[now.getDay()] + ", " + monName[now.getMonth()] + " 
 
"+now.getDate() + " " +  timeValue + "</b>";
 
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock() 
{
    stopclock();
    showtime();
}
// End -->
 
</script>
 
</head>
 
<body onload="startclock();">
<b  style="color:#000000; font-size:medium; font-family:Verdana; font-weight:bold">Clock Time</b>:: 
<span id="timeDisplay" style="color:#000000; font-size:medium; font-family:Verdana; font-weight:bold"></span>
</body>
</html>

Author: Pavan

I am asp.net developer have good knowledge of Asp.net ver 05,08,10 and good hand in sql server.Proficient in Object Oriented Programming and javascript, jQuery. Achievements - Integrate Spotfire, appnexus API ASP.net with sql server. Hobbies - Blogging ,Games, Movies ,Teaching,Keeping myself update with new technologies