-
-
Save johnjullies/e849ca298293b5cf0d35 to your computer and use it in GitHub Desktop.
JavaScript: Convert milliseconds to object with days, hours, minutes, and 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 convertMS(ms) { | |
var y, mo, d, h, m, s; | |
s = Math.floor(ms / 1000); | |
m = Math.floor(s / 60); | |
s = s % 60; | |
h = Math.floor(m / 60); | |
m = m % 60; | |
d = Math.floor(h / 24); | |
h = h % 24; | |
mo = Math.floor(d / 30); | |
d = d % 30; | |
d = Math.floor(d / 7); | |
y = Math.floor(mo / 12); | |
mo = mo % 12; | |
return { y: y, mo: mo, d: d, h: h, m: m, s: s }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added years and months property from @remino's version.