Soundcloud's API gives the duration of it's tracks as milliseconds. JSON looks like this:
"duration": 298999
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:
4:59
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.
var ms = 298999,
min = Math.floor((ms/1000/60) << 0),
sec = Math.floor((ms/1000) % 60);
console.log(min + ':' + sec);
Thanks for your help!
If you could add in support for hours, too, I would be grateful.
4:58
. Please provide an input that leads to the unexpected output. – Ruction3:7
(maybe should be3:07
) for me. Where do you see 99 in there? – Ruction<< 0
just did the same as yourMath.floor
… – Ruction