Users Pricing

articles

home / developersection / articles / creating simple timer in java script

Creating Simple Timer in Java Script

Anonymous User 9355 15 Mar 2011 Updated 07 Sep 2019

In this demonstration we are going to learn how to create a simple timer control in java script. For creating a timer control we need to create a Date () object. Then we can retrieve all information such as hours, minutes, seconds and milliseconds. Then we can use setTime(“dispTime()”,1) method to call it recursively.

Following function creates a timer function
function dispTime() {
            var date = new Date();
            document.getElementById("dd1").innerHTML = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + ":" + date.getMilliseconds();
            setTimeout("dispTime()",1);
}

Following html code design a simple UI in html.

Code:
<body onload="dispTime()">
    <div id="dd1">
    </div>
</body>
Output of the following code snippet is as follows

Creating Simple Timer in Java Script

Creating Simple Timer in Java Script


I am a content writter !


1 Comments