Last active
November 30, 2020 19:40
-
-
Save johnatandias/9ce36e93fda32948df57291c4b32f3e8 to your computer and use it in GitHub Desktop.
Convert Milliseconds to Hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function msToTime(duration = 0) { | |
const seconds = `0${Math.floor((duration / 1000) % 60)}`.slice(-2) | |
const minutes = `0${Math.floor((duration / (1000 * 60)) % 60)}`.slice(-2) | |
const hours = `0${Math.floor((duration / (1000 * 60 * 60)) % 24)}`.slice(-2) | |
return `${hours}:${minutes}:${seconds}`; | |
} | |
console.log(msToTime(97739)) // 00:01:37 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment