For a long time, the best option was moment.js. But now it seems like browsers have implemented those features.

Check out DateTimeFormat and RelativeTimeFormat. The functions handle all locales and even handle time zones.

It looks like DateTimeFormat has been available since Chrome 24, and RelativeTimeFormat since Chrome 71. Based on these Chrome release dates, it means DateTimeFormat has been available since 2013, and RelativeTimeFormat since late 2018. I'm a few years late to the party.

DateTimeFormat has been available since Chrome 24.