KnowledgeSeeker
KnowledgeSeeker

Reputation: 1088

Moment js display different behavior of relative, calendar and multiple local support

I am using momentjs in an angular app and I don't have any code to show here. I tried to play around with it and try to figure it out but ended up in a mess.

What I want to happen is I have a createdAt property that I am retrieving to some API server and I want to display it like the facebook way for displaying time relative in the post but in a nicer way.

For example:

if within this day display relative time

  1. A few seconds ago.
  2. A minute ago
  3. 2 minutes ago (if more than 1 minute)
  4. An hour ago (if 1 hour ago)
  5. 2 hours ago (if more than 1 hour until 24 hours ago)
  6. Yesterday at 10:03 am (If 1 day after)
  7. Last Tuesday at 7:30 pm (After 48 hours)
  8. Last month at June 18 on 7:30 pm (After a month)

and the list goes on for year.

I know I can do this using multiple conditions but ended up messing it. Is there a better way to do this?

Can someone shed some light for me?

Upvotes: 0

Views: 305

Answers (0)

Related Questions