-
-
Save mjunaidi/a3a8e7276428b125f2d47a70e377a64c to your computer and use it in GitHub Desktop.
JavaScript: Convert milliseconds to object with days, hours, 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 convertMS( milliseconds ) { | |
var day, hour, minute, seconds; | |
seconds = Math.floor(milliseconds / 1000); | |
minute = Math.floor(seconds / 60); | |
seconds = seconds % 60; | |
hour = Math.floor(minute / 60); | |
minute = minute % 60; | |
day = Math.floor(hour / 24); | |
hour = hour % 24; | |
return { | |
day: day, | |
hour: hour, | |
minute: minute, | |
seconds: seconds | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment