Skip to content

Instantly share code, notes, and snippets.

@hwindo
Last active October 4, 2017 09:36
Show Gist options
  • Save hwindo/5303e9484f767f4bef03b062d0a7188c to your computer and use it in GitHub Desktop.
Save hwindo/5303e9484f767f4bef03b062d0a7188c to your computer and use it in GitHub Desktop.
convert milliseconds into Minutes and Seconds
function msToTime(duration) {
var milliseconds = parseInt((duration%1000)/100)
, seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}