Time display using JavaScript

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>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.