Skip to content

Instantly share code, notes, and snippets.

@thangngoc89
Forked from remino/msconvert.js
Created December 30, 2015 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thangngoc89/c5638ff7e89965a17b63 to your computer and use it in GitHub Desktop.
Save thangngoc89/c5638ff7e89965a17b63 to your computer and use it in GitHub Desktop.
JavaScript: Convert milliseconds to object with days, hours, minutes, and seconds
function convertMS(ms) {
var 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;
return { 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