In the moment.js documentation the following example is given:
moment.duration(1, "minutes").humanize(); // a minute
moment.duration(2, "minutes").humanize(); // 2 minutes
moment.duration(24, "hours").humanize(); // a day
I need to have for this call
moment.duration(1, "minutes").humanize();
an output "1 minute" and I want to have for this string
moment.duration(24, "hours").humanize();
an output "24 hours".
I cannot just replace the "a" word with 1 because it is going to be used for many different languages.
Is that possible? Maybe some simple config / workaround / non-documented feature?
From the moment.js documentation you can customize it like so:
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"
}
});
I know this solution is not perfect, but couldn't find any better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With