title: How to format time properly
body: <p>I am trying to format time. I have a function that returns seconds, minutes, and hours, but I have an issue with the minutes. After the minute hits 60, I would like to reset the minute time to 0 and restart the clock. Any ideas?</p>
  
  <pre><code>function formatTime(seconds) {
    hours = Math.floor((seconds / 60) / 60);
    hours = (hours &gt;= 10) ? minutes : "0" + hours;
    minutes = Math.floor(seconds / 60);
    minutes = (minutes &gt;= 10) ? minutes : "0" + minutes;
    seconds = Math.floor(seconds % 60);
    seconds = (seconds &gt;= 10) ? seconds : "0" + seconds;
  
    if (duration &gt;= hours) {
      return hours + ":" + minutes + ":" + seconds;
    } else {
      return minutes + ":" + seconds;
    }
  }
  </code></pre>
  
  <p>If you have any other questions, let me know. This function is being used to format an audio clip's duration counter.</p>