Time display using JavaScript
The function setTimeout() in function is used and here is its general syntax.
timerID = setTimeout(expression, msec);
timerID is the identifier used to identify the current timeout function.
expression is the statement that is to be executed after the specified time has ticked off.
msec is the duration of time in milliseconds after which the expression will be executed.
<html>
<head>
<script type=”text/javascript”>
var timerID = 0;
var tStart = null;
function Start() {
var tDate = new Date();
var h =tDate.getHours();
var m =tDate.getMinutes();
var s =tDate.getSeconds();
var dd=”am”;
if(h > 12)
{
h=h-12;
dd=”pm”;
}
document.getElementById(”time_id”).innerHTML =h+”:”+ m + “:”+ s +”:” + dd;
timerID = setTimeout(”Start()”, 1000);
}
</script>
</head>
<body onload=’Start();’>
<div id=”time_id”></div>
</body>
</html>
