Standard built-ins

Intl.DateTimeFormat.prototype.formatToParts()

Try the free JavaScript compiler

Return ordered typed date/time components for display without relying on fixed text offsets.

Formal Syntax & Structure

javascript syntaxjavascript
formatter.formatToParts([date])

Parameters & Attributes

NameTypeDescription
dateDate | NumberInstant to format.

Return Value

Array

Objects with type and value.

Working Example

Example Snippetjavascript
const f=new Intl.DateTimeFormat("en-US",{timeZone:"UTC",year:"numeric"});console.log(f.formatToParts(0)[0].type);
JavaScript Reference