Intl.DateTimeFormat

Intl.DateTimeFormat.prototype.formatToParts

Formats a date into an array of objects representing the formatted date in parts

Syntax

JavaScript
dateTimeFormat.formatToParts(date?)

Parameters

ParameterTypeDescription
dateDate | numberThe date to format into parts

Return Value

An array of objects with type and value properties

Examples

Basic Usage
const fmt = new Intl.DateTimeFormat('en-US', { dateStyle: 'full' })
const parts = fmt.formatToParts(new Date())
console.log(parts)
Practical Example
function extractMonth(date: Date, locale: string): string {
  const fmt = new Intl.DateTimeFormat(locale, { month: 'long' })
  const parts = fmt.formatToParts(date)
  return parts.find(p => p.type === 'month')?.value || ''
}
Advanced Usage
const fmt = new Intl.DateTimeFormat('en-US', {
  year: 'numeric',
  month: '2-digit',
  day: '2-digit'
})
const parts = fmt.formatToParts(new Date())
const obj = Object.fromEntries(parts.map(p => [p.type, p.value]))
console.log(obj)

Understanding Intl.DateTimeFormat.prototype.formatToParts

The Intl.DateTimeFormat.prototype.formatToParts method in JavaScript formats a date into an array of objects representing the formatted date in parts. It belongs to the Intl.DateTimeFormat object and is one of the most widely used methods for working with intl.datetimeformat values in modern JavaScript and TypeScript applications.

The method signature is dateTimeFormat.formatToParts(date?). It accepts 1 parameter: date. When called, it returns an array of objects with type and value properties. Understanding when and how to use formatToParts() helps you write more expressive, readable code.

Common use cases for Intl.DateTimeFormat.prototype.formatToParts include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like intl-datetimeformat-format, intl-datetimeformat, intl-numberformat-formattoparts, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Intl.DateTimeFormat.prototype.formatToParts is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Intl.DateTimeFormat Methods

Other methods in the Intl.DateTimeFormat object

Related Tools

More Intl.DateTimeFormat Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.