Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full humanized durations in moment.js

Tags:

momentjs

I tried this in moment.js

moment.duration(375,'days').humanize() 

and get "a year" as answer, but I would expect "a year and 10 days". Is there a way in moment.js to get the full humanized value?

like image 672
husayt Avatar asked Jul 02 '12 19:07

husayt


2 Answers

Moment.js is providing the fromNow function to get time durations in human readable fromat, see http://momentjs.com/docs/#/displaying/fromnow/

Example:

moment([2007, 0, 29]).fromNow(); // 4 years ago moment().subtract(375, 'days').fromNow(); // a year ago 

You need to use third party lib as suggested by @Fluffy

like image 177
Kishore Relangi Avatar answered Sep 21 '22 11:09

Kishore Relangi


I found this small lib, that only display duration (if you don't really need all the features of moment.js)

https://github.com/EvanHahn/HumanizeDuration.js

like image 30
Nicolas C Avatar answered Sep 22 '22 11:09

Nicolas C