Standard built-ins
Intl.DateTimeFormat.prototype.formatToParts()
Return ordered typed date/time components for display without relying on fixed text offsets.
Formal Syntax & Structure
javascript syntaxjavascript
formatter.formatToParts([date])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| date | Date | Number | Instant 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);