Standard built-ins

Intl.RelativeTimeFormat.prototype.formatToParts()

Try the free JavaScript compiler

Return typed parts of relative expression, including unit annotations for numeric components.

Formal Syntax & Structure

javascript syntaxjavascript
formatter.formatToParts(value, unit)

Parameters & Attributes

NameTypeDescription
valueNumberSigned quantity.
unitStringSupported temporal unit, e.g. day or hour.

Return Value

Array

Relative-time parts.

Working Example

Example Snippetjavascript
const f=new Intl.RelativeTimeFormat("en");console.log(f.formatToParts(-2,"day").some(p=>p.type==="integer"));
JavaScript Reference