DEV Community

Cover image for Formatting date phrases becomes easy in javascript
Shubham
Shubham

Posted on • Originally published at Medium on

Formatting date phrases becomes easy in javascript

Modern web applications often use phrases like “yesterday”, “42 seconds ago”, or “in 3 months” instead of full dates and timestamps. There is no direct solution given by javascript until now. You have to write manually function which is cumbersome in itself or rely on any third party library like moment.js etc. But you don't have to rely on any third party library to achieve this.

The brand new Intl.RelativeTimeFormat API shifts that burden to the JavaScript engine, which can ship the locale data and make it directly available to JavaScript developers. Intl.RelativeTimeFormat enables localized formatting of relative times without sacrificing performance.

These are some examples to get you better idea :-)

Not only this you can convert these into your native language. For example :

That’s all from my side. Congrats yourself for learning new thing. You can explore more on mdn docs.

Top comments (0)