moment().startOf('day').fromNow() //6 hours ago.
如何更改以上内容以显示6h?
答案 0 :(得分:8)
您可以定义自定义区域设置字符串。
moment.locale('en', {
relativeTime : {
future: "in %s",
past: "%s ago",
s: "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"
}
});
如果您需要额外的处理,可以将令牌设置为如下所示的函数,该函数应返回一个字符串。
function relativeTime(number, withoutSuffix, key, isFuture) {
return aString;
}