Standard built-ins

Intl.RelativeTimeFormat

Try the free JavaScript compiler

Format signed quantities in temporal units; does not calculate the quantity.

Formal Syntax & Structure

javascript syntaxjavascript
new Intl.RelativeTimeFormat([locales], [options])

Parameters & Attributes

NameTypeDescription
localesString | ArrayRequested locale tag or prioritized locale list.
optionsObjectFormatting options.

Return Value

Intl.RelativeTimeFormat

New formatter.

Working Example

Example Snippetjavascript
console.log(new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(-1,"day"));
JavaScript Reference