Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Forked from remino/msconvert.js
Last active April 8, 2018 02:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pbojinov/4733130 to your computer and use it in GitHub Desktop.
Save pbojinov/4733130 to your computer and use it in GitHub Desktop.
/**
* Convert milliseconds to Hour:Minute:Seconds || Minute:Seconds
*
* @param {int} milliseconds
* @return {Object} h = hour, m = minute, s = 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;
h = h % 24;
return {h: h, m: m, s: s, total: (h > 0) ? (h + ':' + m + ':' + s) : (m + ':' + s)};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment