javascript - How to get duration in weeks with Moment.js? -
I use I would like to receive "2 weeks ago" now, but the code below returns the periods in days " Absolute "(" week ", 2) .from (d) //" 14 weeks ago " How can I get You can do this easily with a custom callback function. 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"
Moment (D) "2 weeks ago" "Return" of 2 weeks before "I / O" 2 weeks ago ""
moment.js ?
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
Post a Comment