Skip to content

Instantly share code, notes, and snippets.

@nathantaal
Forked from remino/msconvert.js
Last active November 11, 2017 11:10
Show Gist options
  • Select an option

  • Save nathantaal/b66f75cc10bd85c8ce9e953b07fe800b to your computer and use it in GitHub Desktop.

Select an option

Save nathantaal/b66f75cc10bd85c8ce9e953b07fe800b to your computer and use it in GitHub Desktop.
JavaScript: Convert milliseconds to object with days, hours, minutes, and seconds
formatDate(ms){
let 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;
if(h<10){
h = '0'+h;
}
if(m<10){
m = '0'+m;
}
if(s<10){
s = '0'+s;
}
return ''+h+':'+m+':'+s+'';
}
@nathantaal
Copy link
Author

Returns double numbers as a String.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment