title: JavaScript display duration
body: <p>I'm trying to make a little counter that display how much a movie has played, like on YouTube.</p>
  
  <p>I want the time to output a  like this:</p>
  
  <pre><code>&lt;div id="timeInfo"&gt;00:23&lt;/div&gt;
  </code></pre>
  
  <p>How do I achieve this?
  I tried the following without success:</p>
  
  <pre><code>function infTime (){
      timeInfo.innerHTML = formatTime(video.currentTime);
  
      if (video.duration) {
          timeInfo.innerHTML = formatTime(video.duration);
      }
  }
  
  function formatTime (seconds) {
      seconds = Math.round(seconds);
  
      minutes = Math.floor(seconds / 60);
      minutes = (minutes &gt;= 10) ? minutes : "0" + minutes;
  
      seconds = Math.floor(seconds % 60);
      seconds = (seconds &gt;= 10) ? seconds : "0" + seconds;
  
      return minutes + ":" + seconds;
  }
  </code></pre>