Shortened relative time (Instagram style) using impulses?

moment().startOf('day').fromNow() //6 hours ago.

How can I change above to show instead of 6h?

+4
source share
1 answer

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 need additional processing, you can set the token as a function, as shown below, the function should return a string.

function (number, withoutSuffix, key, isFuture) {
    return string;
}
+7
source

All Articles