In the moment.js documentation给出了以下示例:
moment.duration(1, "minutes").humanize(); // a minute
moment.duration(2, "minutes").humanize(); // 2 minutes
moment.duration(24, "hours").humanize(); // a day
我需要有这个电话
moment.duration(1, "minutes").humanize();
一个输出"1分钟“,我希望这个字符串
moment.duration(24, "hours").humanize();
A输出"24小时“。
我不能简单地将"a“替换为1,因为它将用于许多不同的语言。
这有可能吗?也许是一些简单的配置/解决方法/未记录的功能?
发布于 2015-08-04 16:47:29
在moment.js documentation中,您可以像这样对其进行自定义:
moment.locale('en', {
relativeTime : {
future: "in %s",
past: "%s ago",
s: "seconds",
m: "a minute", //change that to "%d minute"
mm: "%d minutes",
h: "an hour", //here too
hh: "%d hours",
d: "a day", //and here
dd: "%d days",
M: "a month", //and so on...
MM: "%d months",
y: "a year",
yy: "%d years"
}
});
我知道这个解决方案并不完美,但也找不到更好的了。
发布于 2018-10-01 16:34:58
你可以像moment.relativeTimeThreshold('h',25)一样使用relative time threshold从moment.duration(24, "hours").humanize();
with moment输出"24小时“
https://stackoverflow.com/questions/31804518
复制相似问题