Skip to content

Instantly share code, notes, and snippets.

@ssnau
Created June 3, 2015 15:25
Show Gist options
  • Save ssnau/ac5d41d58ba53695b218 to your computer and use it in GitHub Desktop.
Save ssnau/ac5d41d58ba53695b218 to your computer and use it in GitHub Desktop.
moment humanize
function duration(ms) {
var du = moment.duration(ms / 1000, 'seconds');
var y = du.years();
var mon = du.months();
var d = du.days();
var h = du.hours();
var m = du.minutes();
var s = du.seconds();
return [
y && (y + 'Y'),
mon && (mon + 'M'),
d && (d + 'D'),
h && (h + 'h'),
m && (m + 'm'),
s && (s + 's')
].filter(Boolean).join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment