Moment.js:更改默认的humanize()行为

smn*_*brv 4 javascript momentjs

在moment.js文档中,给出了以下示例:

moment.duration(1, "minutes").humanize(); // a minute
moment.duration(2, "minutes").humanize(); // 2 minutes
moment.duration(24, "hours").humanize();  // a day
Run Code Online (Sandbox Code Playgroud)

我需要这个电话

moment.duration(1, "minutes").humanize();
Run Code Online (Sandbox Code Playgroud)

输出“ 1分钟”,我想要这个字符串

moment.duration(24, "hours").humanize();
Run Code Online (Sandbox Code Playgroud)

输出“ 24小时”。

我不能只用1代替“ a”一词,因为它将用于许多不同的语言。

那可能吗?也许一些简单的配置/解决方法/未记录的功能?

Are*_*ski 5

moment.js文档,您可以像这样自定义它:

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"
    }
});
Run Code Online (Sandbox Code Playgroud)

我知道此解决方案并不完美,但找不到更好的解决方案。