# Countdown Timer

**URL:** <https://forum.wixstudio.com/t/countdown-timer/13384>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 1, 2018, 12:21am UTC](https://forum.wixstudio.com/t/countdown-timer/13384 "2018-12-01T00:21:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![akemp18](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@akemp18](https://forum.wixstudio.com/u/akemp18)\
**Post date:** [December 1, 2018, 12:21am UTC](https://forum.wixstudio.com/t/countdown-timer/13384/1 "2018-12-01T00:21:27Z")

</div>

Hi, I’m trying to create a timer that counts down from 1 hour in minutes and seconds. I want the timer to show as being in a box and to start when a button is pressed. Any ideas?

---

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [December 1, 2018, 12:02pm UTC](https://forum.wixstudio.com/t/countdown-timer/13384/2 "2018-12-01T12:02:17Z")

</div>

This code can easily be modified and started on button click instead of page onReady.

```javascript
$w.onReady(function () {
 var countDownDate = new Date("Dec 1, 2018 12:59:25").getTime(); // Countdown date and time

 var x = setInterval(function() {
 var now = new Date().getTime();
 var distance = countDownDate - now;
 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
 
        $w("#countDownTimer").text = hours + "h " + minutes + "m " + seconds + "s ";
 
 if (distance < 0) {
            clearInterval(x);
            $w("#countDownTimer").text = "EXPIRED";
        }
    }, 1000);
 
});

```

---

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [December 1, 2018, 12:39pm UTC](https://forum.wixstudio.com/t/countdown-timer/13384/3 "2018-12-01T12:39:53Z")

</div>

Also remember that this way might make the browser stop responding because it runs code in the local browser.

---

<div class="post-metadata">

**Author:** ![akemp18](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@akemp18](https://forum.wixstudio.com/u/akemp18)\
**Post date:** [December 1, 2018, 6:22pm UTC](https://forum.wixstudio.com/t/countdown-timer/13384/4 "2018-12-01T18:22:47Z")

</div>

@andreas-kviby I’m not trying to countdown to a date. Just a simple one hour timer shown in minutes and seconds that starts on a button click

---

<div class="post-metadata">

**Author:** ![bmelida99](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bmelida99/32/6847_2.png) [@bmelida99](https://forum.wixstudio.com/u/bmelida99)\
**Post date:** [January 27, 2019, 6:12pm UTC](https://forum.wixstudio.com/t/countdown-timer/13384/5 "2019-01-27T18:12:58Z")

</div>

used the code as the base for my countdown it is great,thank you
