Created
June 3, 2015 15:25
-
-
Save ssnau/ac5d41d58ba53695b218 to your computer and use it in GitHub Desktop.
moment humanize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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