I use moment.js to get relative time. It returns, for example, "6 hours ago". But I would like to get the short version like "6h".
I read the doc: http://momentjs.com/docs/#/customization/relative-time/
But if I change:
moment.updateLocale('en', {
relativeTime : {
future: "in %s",
past: "%s ago",
s : 'a few seconds',
ss : '%d seconds',
m: "a minute",
mm: "%d minutes",
h: "an hour",
hh: "%d hours",
d: "a day",
dd: "%d days",
M: "a month",
MM: "%d months",
y: "a year",
yy: "%d years"
}
});
to
moment.updateLocale('en', {
relativeTime : {
future: "in %s",
past: "%s",
s : 'a few seconds',
ss : '%d h',
m: "a minute",
mm: "%d m",
h: "an hour",
hh: "%d h",
d: "a day",
dd: "%d d",
M: "a month",
MM: "%d m",
y: "a year",
yy: "%d y"
}
});
I get the error:
Cannot read property 'humanize' of undefined at Moment.from (moment.js:3313)
When I call
moment(value).fromNow()
Here, value is a date as Date type
Is it possible to get short format version with moment.js ?