Created
January 23, 2017 22:47
-
-
Save irokhes/0cc3222078ac81a58f86c1a1c35a40be to your computer and use it in GitHub Desktop.
Javascript => convert time in milliseconds to hours, minutes ands seconds
This file contains hidden or 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) { | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment