Snippet for a rather popular requirement. Formatting a date in a nice way, using infamous "time ago" function. This is the basic version which I adapt to fit a specific project. To keep it easily customizable to your needs, I haven't packaged it up.
Just pass a date to it, and function will return one of the seven possible formats:
now- if no more than five seconds elapsed
about a minute ago- in no more than ninety seconds elapsed
24 minutes ago- for anything in the last hour
Today at 11:19- for today
Yesterday at 7:32- for yesterday
15. February at 17:45- for dates in the current year
23. October 2017. at 0:59- for anything else
Feel free to play with it and add more cases if you need them.
; // --- Main function
Update, August 2020