Skip to content

Instantly share code, notes, and snippets.

@hero9
Last active August 24, 2018 07:07
Show Gist options
  • Save hero9/1571748d2929bb76eb74214a9fa5990f to your computer and use it in GitHub Desktop.
Save hero9/1571748d2929bb76eb74214a9fa5990f to your computer and use it in GitHub Desktop.
formatDays = function (d) {
var days = Math.floor(d / 86400),
hours = Math.floor((d - (days * 86400)) / 3600),
minutes = Math.floor((d - (days * 86400) - (hours * 3600)) / 60),
seconds = d - (days * 86400) - (hours * 3600) - (minutes * 60);
var output = '';
if (seconds) {
output = seconds + 's';
}
if (minutes) {
output = minutes + 'm ' + output;
}
if (hours) {
output = hours + 'h ' + output;
}
if (days) {
output = days + 'd ' + output;
}
return output;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment