我使用moment.js來獲得相對時間。例如,它返回「6小時前」。但我想獲得像「6h」這樣的短版。如何更改fromNow調用的輸出?
我讀的文檔:http://momentjs.com/docs/#/customization/relative-time/
但是,如果我改變:
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"
}
});
到
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"
}
});
我得到的錯誤:
Cannot read property 'humanize' of undefined at Moment.from (moment.js:3313)
當我打電話
moment(value).fromNow()
這裏,值是一個日期,日期型
是否有可能獲得短格式版本moment.js?
所以,你不與第一對象得到錯誤? –
另外,你使用的是什麼版本的Moment.js? –
我使用2.18.1 –