Countdown Timer

The essential marketing tool. Use this script to count down to a product launch, a holiday, or an event deadline.

Next New Year
...

Copy the Script

<p id="timer"></p>

<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 1, 2030 00:00:00").getTime();

var x = setInterval(function() {
  var now = new Date().getTime();
  var distance = countDownDate - now;

  // Time calculations
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  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);

  document.getElementById("timer").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";

  // If the count down is finished, write some text
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("timer").innerHTML = "EXPIRED";
  }
}, 1000);
</script>

Frequently Asked Questions

The script includes a check `if (distance < 0)`. You can use this to display text like 'EXPIRED' or redirect the user to another page.

Yes. The output is a simple string, but you can target individual units by wrapping them in `` tags if you modify the JavaScript string concatenation.

No. Because it targets a specific calendar date (absolute time), it will show the correct remaining time regardless of page reloads.