Favorites

JavaScript Intl.RelativeTimeFormat Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Intl.RelativeTimeFormat
JavaScript Internationalization · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

Intl.RelativeTimeFormat formats relative times, such as 3 days ago or in 2 hours, in any language.

Description

Intl.RelativeTimeFormat produces phrases describing a time relative to now, such as "2 days ago" or "in 3 weeks", correctly translated and pluralized for the locale. Call format(value, unit) with a positive or negative number and a unit such as 'second', 'minute', 'hour', 'day', 'week', 'month' or 'year'.

With numeric: 'auto', it uses words like "yesterday" and "next week" where the language has them. You still have to work out the difference and choose the unit yourself.

The style option chooses between long ("in 3 months"), short ("in 3 mo.") and narrow forms, and formatToParts() splits the result so you can style the number separately. It doesn't decide which unit to use; a common approach is to compare the difference in seconds against thresholds for minutes, hours, days and so on, and pick the largest unit that fits.

Creating

new Intl.RelativeTimeFormat(locales, options)

Example

const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
console.log(rtf.format(-1, 'day'));
console.log(rtf.format(3, 'hour'));
console.log(rtf.format(-2, 'week'));
console.log(new Intl.RelativeTimeFormat('es').format(-5, 'minute'));

Browser Support

The following information will show you the current browser support for the Intl.RelativeTimeFormat object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee