moment().startOf('day').fromNow() //6 hours ago.
How can I change the above to show 6h instead?
You can define custom locale strings.
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"
}
});
If you require additional processing, you can set the token as a function like shown below, the function should return a string.
function relativeTime(number, withoutSuffix, key, isFuture) {
return aString;
}
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