title: Countdown timer using Moment js
body: <p>I am making a countdown timer for an event page, i used moment js for this.</p>
  <p>Here is <a href="http://jsfiddle.net/wt812nfo/" rel="noreferrer">fiddle</a> for this.</p>
  <p>I am calculating date difference between event date and current date (timestamp), then using &quot;duration&quot; method from moment js.  But the time left is not coming as expected.<br />
  <strong>Expected</strong> - 00:30m:00s<br />
  <strong>Actual</strong> - 5h:59m:00s</p>
  <p>Code :</p>
  <pre><code>&lt;script&gt;
    $(document).ready(function(){
  
      var eventTime = '1366549200';
      var currentTime = '1366547400';
      var time = eventTime - currentTime;
      var duration = moment.duration(time*1000, 'milliseconds');
      var interval = 1000;
  
      setInterval(function(){
        duration = moment.duration(duration.asMilliseconds() - interval, 'milliseconds');
        $('.countdown').text(moment(duration.asMilliseconds()).format('H[h]:mm[m]:ss[s]'));
      }, interval);
    });
    &lt;/script&gt;
  </code></pre>
  <p>I read the momentjs documentation to figure out the problem, but no luck.</p>
  <p>Thanks for your time.</p>
  <p><strong>Update :</strong></p>
  <p>I end up doing like this :</p>
  <pre><code>&lt;script&gt;
    $(document).ready(function(){
  
      var eventTime = '1366549200';
      var currentTime = '1366547400';
      var leftTime = eventTime - currentTime;//Now i am passing the left time from controller itself which handles timezone stuff (UTC), just to simply question i used harcoded values.
      var duration = moment.duration(leftTime, 'seconds');
      var interval = 1000;
  
      setInterval(function(){
        // Time Out check
        if (duration.asSeconds() &lt;= 0) {
          clearInterval(intervalId);
          window.location.reload(true); #skip the cache and reload the page from the server
        }
  
        //Otherwise
        duration = moment.duration(duration.asSeconds() - 1, 'seconds');
        $('.countdown').text(duration.days() + 'd:' + duration.hours()+ 'h:' + duration.minutes()+ 'm:' + duration.seconds() + 's');
      }, interval);
    });
    &lt;/script&gt;
  </code></pre>
  <p><a href="http://jsfiddle.net/arpit/cxyms" rel="noreferrer">JS Fiddle</a>.</p>