countdown.js setting it to midday

260 views Asked by At

I recently discovered this (countdown.js) beautiful script. But it is not documented. So I have huge difficulty in trying to understand its algorithm.

My Goal I am trying to set a counter just like the one used by amazon for delivery time left.

So it should countdown until midday and reset itself at midday for the next midday. And obviously it also changes the text showed just like amazon.

EXAMPLE

June 15, 8.00 AM; the timer should be like this:

Want it tomorrow, June 16? Order within 4 hrs 0 mins and choose One-Day Shipping at checkout.

June 15, 1.00 PM; the timer should be like this:

Want it on June 17? Order within 23 hrs 0 mins and choose One-Day Shipping at checkout.

I hope I'm clear enough. Thank you in advance.

Here is an example that I took from a site but it ends at midnight:

<html>

<head>
</head>

<body>
  <h4 id="midnight-countdown"></h4>

  <script src="https://smalldo.gs/js/countdown.min.js"></script>
  <script>
    var clock1 = document.getElementById("midnight-countdown"),
      tdy = new Date();
    clock1.innerHTML = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate() + 1)).toString();
    setInterval(function() {
      clock1.innerHTML = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate() + 1)).toString();
    }, 1000);
  </script>
</body>

</html>

1

There are 1 answers

6
Praveen Kumar Purushothaman On

Please include your full time! Not just the date. Syntax here:

var timespan = countdown(start|callback, end|callback, units, max, digits);

In your code:

<h4 id="midnight-countdown"></h4>
</blockquote>
<p>Here is how to do a custom live countdown on your page using pure javascript (no jQuery needed).</p>
<script src="https://smalldo.gs/js/countdown.min.js"></script>
<script>
  var clock1 = document.getElementById("midnight-countdown")
  , tdy = new Date();
  clock1.innerHTML = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate() + 1, tdy.getHours(), tdy.getMinutes()) ).toString();
  setInterval(function(){
    clock1.innerHTML = countdown(new Date(tdy.getFullYear(), tdy.getMonth(), tdy.getDate() + 1, tdy.getHours(), tdy.getMinutes()) ).toString();
  }, 1000);
</script>