CKTIS / JavaScript
Intl.RelativeTimeFormat — formatting relative time
Intl.RelativeTimeFormat creates localized relative-time descriptions. Its format(value, unit) method takes a number and a unit, not a date; calculating the time difference remains the application's responsibility.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
const rtf = new Intl.RelativeTimeFormat(locales, { numeric: "auto", style: "long" });
rtf.format(value, unit);Intl.RelativeTimeFormat belongs to the ECMA-402 internationalization standard, not the DOM APIs. Construct an instance with new. Here, RelativeTimeFormat.format means the instance method Intl.RelativeTimeFormat.prototype.format(value, unit), which returns text. Negative numbers describe the past and positive numbers the future; the method does not calculate differences between dates.
unit accepts second, minute, hour, day, week, month, quarter, year, and their English plural forms. An unsupported unit, NaN, or infinity causes a RangeError.
The default numeric: "always" skips special terms such as yesterday, but a locale’s pattern can express quantity without an explicit number. For example, Arabic can use a dual noun form for two days without a separate numeric part. numeric: "auto" allows expressions such as yesterday when available. style accepts long (the default), short, or narrow.
The example explicitly selects en and fixed values. Exact text depends on locale data. Check constructor and required-locale availability in the target browser; Node 24 in a repository does not establish browser support.
Examples
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
console.log(rtf.format(-1, "day"));
console.log(rtf.format(1, "day"));Result
yesterday tomorrow
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.