javascript - How to get duration in weeks with Moment.js? -


I use moment.js to format periods in human readable format. For example ( d is a a date is a object):

 moment (d). Subtract ("day", 3) .from (d) // "3 days ago"  

I would like to receive "2 weeks ago" now, but the code below returns the periods in days

 Moment (D) "2 weeks ago" "Return" of 2 weeks before "I / O" 2 weeks ago ""  " 

" Absolute "(" week ", 2) .from (d) //" 14 weeks ago " How can I get moment.js ?

You can do this easily with a custom callback function. moment .relativeTime.dd = function (number) {// round var week for the closest number of weeks = mathematics. (Number / 7); If (number & lt; 7) {// if less than a week, use day's return number + "day"; } Other {// week to week week return "week" + (week === 1? "": "S"); }}



Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -