Using moment to display time of an activity


Hi guys,

I’ve been using the awesome momentjs library to format and display dates in my app. So far, I’ve been able to get stuff like ‘4 days ago’, ‘3 weeks left’ to show.

However, there is a feed page in the app, and I want to be able to format the date of each post to display as:
‘1d’, ‘3w’, ‘2y’ for days, weeks and years. Also, if the post was just created, it should display something like ‘Just Now’. I’ve been trying to get this working for some time now. How do I get this done?

Thanks for your help guys.


This is a MomentJS question, not an Ionic one, but you may be able to customise the Relative Time format as per this link:

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:  "1 d",
        dd: "%d d",
        M:  "1 m",
        MM: "%d m",
        y:  "1 y",
        yy: "%d y"


Alright. Thanks a lot