Skip to content

Instantly share code, notes, and snippets.

@GianfrancoFrau
Last active January 25, 2024 20:12
Show Gist options
  • Save GianfrancoFrau/241c3326b0d90a5bf6631e4f8bcf571a to your computer and use it in GitHub Desktop.
Save GianfrancoFrau/241c3326b0d90a5bf6631e4f8bcf571a to your computer and use it in GitHub Desktop.
msToTime.js
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((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;
}
// test
console.log(msToTime(300000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment