title: javascript countdown time formatting
body: <p>I have a javascript countdown you can see <a href="http://jsfiddle.net/0kppf1m2/" rel="nofollow">here</a>.</p>
  
  <p>I set deadline time in this line:</p>
  
  <pre><code>var deadline = '12/15/2015';
  </code></pre>
  
  <p>It's MM/DD/YYYY format. I would like to change it to DD/MM/YYYY format.
  How can I change it?</p>
  
  <p>Another thing is countdown goes to minus when deadline is end.
  How can I set some text like "Deadline is past." when countdown ends?</p>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>function getTimeRemaining(endtime) {
    var t = Date.parse(endtime) - Date.now();
    var seconds = Math.floor((t / 1000) % 60);
    var minutes = Math.floor((t / 1000 / 60) % 60);
    var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
    var days = Math.floor(t / (1000 * 60 * 60 * 24));
    return {
      'total': t,
      'days': days,
      'hours': hours,
      'minutes': minutes,
      'seconds': seconds
    };
  }
  
  function initializeClock(id, endtime) {
    var clock = document.getElementById(id);
    var daysSpan = clock.querySelector('.days');
    var hoursSpan = clock.querySelector('.hours');
    var minutesSpan = clock.querySelector('.minutes');
    var secondsSpan = clock.querySelector('.seconds');
  
    function updateClock() {
      var t = getTimeRemaining(endtime);
  
      daysSpan.innerHTML = t.days;
      hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
      minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
      secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
  
      if (t.total &lt;= 0) {
        clearInterval(timeinterval);
      }
    }
  
    updateClock();
    var timeinterval = setInterval(updateClock, 1000);
  }
  
  
  var deadline = '12/15/2015';
  
  initializeClock('clockdiv', deadline);
  </code></pre>
  
  <p><strong>html</strong></p>
  
  <pre><code>&lt;div id="clockdiv"&gt;
  
      &lt;span class="days"&gt;&lt;/span&gt;
      Days
  
  
      &lt;span class="hours"&gt;&lt;/span&gt;
      Hours
  
  
      &lt;span class="minutes"&gt;&lt;/span&gt;
      Minutes
  
  
      &lt;span class="seconds"&gt;&lt;/span&gt;
      Seconds
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>jsfiddle</strong>
  <a href="http://jsfiddle.net/0kppf1m2/" rel="nofollow">http://jsfiddle.net/0kppf1m2/</a></p>