title: JavaScript timer to count down from a certain time for a number of hours
body: <p>I have created a countdown timer. The problem is, I am wanting it to count down from midnight clock <code>00:00:00</code> until clock <code>17:00:00</code>.</p>
  
  <p>I have made the timer count down starting at <code>17 hours 00 minutes 00 seconds</code> and it works a treat, but I need a way to take off the time from <code>00:00:00</code> to present from the <code>17 hours</code>.</p>
  
  <p>Here is my JS code</p>
  
  <pre><code>    function startTimer(duration, display) {
      var start = Date.now(),
          diff,
          hours,
          minutes,
          seconds;
  
      function timer() {
          // get the number of seconds that have elapsed since 
          // startTimer() was called
          diff = duration - (((Date.now() - start) / 1000) | 0);
  
          // Setting and displaying hours, minutes, seconds
          hours = (diff / 360) | 0;
          minutes = (diff / 60) | 0;
          seconds = (diff % 60) | 0;
  
          hours = hours &lt; 10 ? "0" + hours : hours;
          minutes = minutes &lt; 10 ? "0" + minutes : minutes;
          seconds = seconds &lt; 10 ? "0" + seconds : seconds;
  
          display.textContent = hours + ":" + minutes + ":" + seconds;
  
          if (diff &lt;= 0) {
              // add one second so that the count down starts at the full duration
              // example 17:00:00 not 16:59:59
              start = Date.now() + 1000;
          }
      };
      // don't want to wait a full second before the timer starts
      timer();
      setInterval(timer, 1000);
  }
  window.onload = function () {
      var timeLeft = 3600 * 17,
          display = document.querySelector('#time');
      startTimer(timeLeft, display);
  };
  </code></pre>
  
  <p>Here is my HTML code:</p>
  
  <pre><code>&lt;div&gt;Order by: &lt;span id="time"&gt;&lt;/span&gt; for Next Day Delivery.&lt;/div&gt;
  </code></pre>
  
  <p>My thoughts were to get the <code>timeLeft = 3600 * 17</code> and take off the diff.</p>