This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
The Intl.RelativeTimeFormat() constructor creates Intl.RelativeTimeFormat objects.
new Intl.RelativeTimeFormat() new Intl.RelativeTimeFormat(locales) new Intl.RelativeTimeFormat(locales, options)
locales OptionalA string with a BCP 47 language tag or an Intl.Locale instance, or an array of such locale identifiers. The runtime's default locale is used when undefined is passed or when none of the specified locale identifiers is supported. For the general form and interpretation of the locales argument, see the parameter description on the Intl main page.
The following Unicode extension key is allowed:
nuSee numberingSystem.
This key can also be set with options (as listed below). When both are set, the options property takes precedence.
options OptionalAn object containing the following properties, in the order they are retrieved (all of them are optional):
localeMatcherThe locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit". For information about this option, see Locale identification and negotiation.
numberingSystemThe numbering system to use for number formatting, such as "arab", "hans", "mathsans", and so on. For a list of supported numbering system types, see Intl.supportedValuesOf(); the default is locale dependent. This option can also be set through the nu Unicode extension key; if both are provided, this options property takes precedence.
styleThe style of the formatted relative time. Possible values are:
"long" (default)E.g., "in 1 month"
"short"E.g., "in 1 mo."
"narrow"E.g., "in 1 mo.". The narrow style could be similar to the short style for some locales.
numericWhether to use numeric values in the output. Possible values are "always" and "auto"; the default is "always". When set to "auto", the output may use more idiomatic phrasing such as "yesterday" instead of "1 day ago".
RangeErrorThrown if locales or options contain invalid values.
The following example shows how to create a relative time formatter using the English language.
// Create a relative time formatter in your locale
// with default values explicitly passed in.
const rtf = new Intl.RelativeTimeFormat("en-US", {
numeric: "always", // other values: "auto"
style: "long", // other values: "short" or "narrow"
});
// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "1 day ago"
// Format relative time using positive value (1).
rtf.format(1, "day"); // "in 1 day"
If the numeric: "auto" option is passed, it will produce the string yesterday or tomorrow instead of 1 day ago or in 1 day. This is useful when you don't want to use numeric values in the output.
// Create a relative time formatter in your locale
// with numeric: "auto" option value passed in.
const rtf = new Intl.RelativeTimeFormat("en-US", { numeric: "auto" });
// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "yesterday"
// Format relative time using positive day unit (1).
rtf.format(1, "day"); // "tomorrow"
When the value is 0, the output may be dependent on the unit. "0 seconds" is represented by the localized version of "now".
rtf.format(0, "second"); // "now" rtf.format(0, "day"); // "today" rtf.format(0, "minute"); // "this minute"
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
RelativeTimeFormat |
71 | 79 | 65 | 58 | 14 | 71 | 65 | 50 | 14 | 10.0 | 71 | 14 | 1.0.0 | 1.8 | 12.0.0 |
locales_parameter |
71 | 79 | 65 | 58 | 14 | 71 | 65 | 50 | 14 | 10.0 | 71 | 14 | 1.0.0 | 1.8 |
13.0.012.0.0–13.0.0Before version 13.0.0, only the locale data foren-US is available by default. When other locales are specified, the RelativeTimeFormat instance silently falls back to en-US. To make full ICU (locale) data available before version 13, see Node.js documentation on the --with-intl option and how to provide the data. |
Intl.RelativeTimeFormatIntlIntl.RelativeTimeFormat on v8.dev (2018)
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat