---
title: "countdown in Javascript"  
description: "countdown in Javascript"  
author: "Anonymous User"  
published: 2018-07-11  
updated: 2018-07-12  
canonical: https://www.mindstick.com/forum/34604/countdown-in-javascript  
category: "webhosting"  
tags: ["web development", "web services", "javascript"]  
reading_time: 2 minutes  

---

# countdown in Javascript

How To Create A [Countdown Timer](https://answers.mindstick.com/qa/109738/how-to-add-a-countdown-timer-to-a-powerpoint-presentation) Using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) ?

\

## Replies

### Reply by Prakash nidhi Verma

How To Create A Countdown [Timer](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) Using JavaScript :

![countdown in Javascript](https://www.mindstick.com/mindstickforums/2eac2e4f-4c3d-4054-beee-9d9aca191462/images/26f8625a-5063-4ab5-b8ca-1760a3861264.png)\

Basics of a countdown timer are :

-Set a valid end date

-Calculate the time remaining

-Convert the time to a usable format

-Output the clock data as a reusable object

-Display the clock on the page, and stop the clock when it reaches zero

Set a Valid End Date :

```
var deadline = new Date("12 july, 2018, 15:55:28").getTime(); 
```

Calculate Remaining Time :

![countdown in Javascript](https://www.mindstick.com/mindstickforums/2eac2e4f-4c3d-4054-beee-9d9aca191462/images/2b992ff6-9b64-4c03-b726-7dce07f4af15.png)

Output the result:

![countdown in Javascript](https://www.mindstick.com/mindstickforums/2eac2e4f-4c3d-4054-beee-9d9aca191462/images/35a01ab2-08b8-4854-9f25-17026c690f6b.png)

Write some text if the countdown is over:

![countdown in Javascript](https://www.mindstick.com/mindstickforums/2eac2e4f-4c3d-4054-beee-9d9aca191462/images/1dc1fa46-ac98-4508-ad95-fb0e479ec619.png)\

```
<!DOCTYPE HTML>
<html>
<head>
<style>
p {
  text-align: center;
  font-size: 60px;
}
</style>
</head>
<body>
<p id="demo"></p>
<script>
var deadline = new Date("July 12, 2018 15:37:25").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var t = deadline - now;
var days = Math.floor(t / (1000 * 60 * 60 * 24));
var hours = Math.floor((t%(1000 * 60 * 60 * 24))/(1000 * 60 * 60));
var minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((t % (1000 * 60)) / 1000);
document.getElementById("demo").innerHTML = days + "d "
+ hours + "h " + minutes + "m " + seconds + "s ";
    if (t < 0) {
        clearInterval(x);
        document.getElementById("demo").innerHTML = "EXPIRED";
    }
}, 1000);
</script>
```


---

Original Source: https://www.mindstick.com/forum/34604/countdown-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
