Getting Relative Time Dates That Are Locale Sensitive With Javascript Intl API

Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

Sometimes, you want to display the dates in a relative form, such as: 2 weeks ago. You can do this by doing some math and string concatenation with the dates, but Intl helps you with this.

When would you use something like this?

Imagine a list of articles, each article has a publication date, but you don't want to show just that. You want to show how much relative time is between the publication date and today (the day the user is reading the list).