JavaScript Relative Time Format

Very simple relative time formatting:

> _relTime = new Intl.RelativeTimeFormat("en")
RelativeTimeFormat [Intl.RelativeTimeFormat] {}
> _relTime.format(-2, "day")
'2 days ago'
> _relTime.format(2, "hour")
'in 2 hours'
> _relTime.format(24, "year")
'in 24 years'
> _relTime.format(0, "month")
'in 0 months'
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s