Course lesson

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

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.

Duration
3 min
Access
Free
Transcript
Needs source

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).