Last active
October 4, 2017 09:36
-
-
Save hwindo/5303e9484f767f4bef03b062d0a7188c to your computer and use it in GitHub Desktop.
convert milliseconds into Minutes and Seconds
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) { | |
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
src:
https://stackoverflow.com/questions/19700283/how-to-convert-time-milliseconds-to-hours-min-sec-format-in-javascript
inspired by source:
https://stackoverflow.com/questions/21294302/converting-milliseconds-to-minutes-and-seconds-with-javascript