title: Converting milliseconds to minutes and seconds with Javascript
body: <p>Soundcloud's API gives the duration of it's tracks as milliseconds. JSON looks like this:</p>
  
  <pre><code>"duration": 298999
  </code></pre>
  
  <p>I've tried many functions I found on here to no avail. I'm just looking for something to convert that number to something like looks like this:</p>
  
  <pre><code>4:59
  </code></pre>
  
  <p>Here's one that got close, but doesn't work. It doesn't stop the seconds at 60. It goes all the way to 99 which makes no sense. Try entering "187810" as a value of ms, for example.</p>
  
  <pre><code>var ms = 298999,
  min = Math.floor((ms/1000/60) &lt;&lt; 0),
  sec = Math.floor((ms/1000) % 60);
  
  console.log(min + ':' + sec);
  </code></pre>
  
  <p>Thanks for your help!</p>
  
  <p>If you could add in support for hours, too, I would be grateful.</p>