---
title: "Creating Simple Timer in Java Script"  
description: "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"  
author: "Anonymous User"  
published: 2011-03-15  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/511/creating-simple-timer-in-java-script  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Creating Simple Timer in Java Script

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](https://www.mindstick.com/mindstickarticle/e98037b8-29cc-4419-9158-a6542e29f276/images/19253f43-bb62-4c64-aaa4-de2ae0b41c95.png)

![Creating Simple Timer in Java Script](https://www.mindstick.com/mindstickarticle/e98037b8-29cc-4419-9158-a6542e29f276/images/9ab64124-4fa7-47e2-8314-b633cf7de678.png)

---

Original Source: https://www.mindstick.com/articles/511/creating-simple-timer-in-java-script

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
