Reputation: 1088
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
A few seconds ago.
A minute ago
2 minutes ago
(if more than 1 minute)An hour ago
(if 1 hour ago)2 hours ago
(if more than 1 hour until 24 hours ago)Yesterday
at 10:03 am (If 1 day after)Last Tuesday
at 7:30 pm (After 48 hours)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