Intl.DurationFormat
Creates an Intl.DurationFormat object that enables locale-sensitive duration formatting
Syntax
new Intl.DurationFormat(locales?, options?)Parameters
| Parameter | Type | Description |
|---|---|---|
| locales | string | string[] | A BCP 47 language tag or array of tags |
| options | object | Options: style (long, short, narrow, digital) and per-unit options |
Return Value
An Intl.DurationFormat object with a format() method
Examples
const df = new Intl.DurationFormat('en', { style: 'long' })
console.log(df.format({ hours: 1, minutes: 30 }))
// '1 hour, 30 minutes'const df = new Intl.DurationFormat('en', { style: 'digital' })
console.log(df.format({ hours: 2, minutes: 5, seconds: 30 }))
// '2:05:30'const df = new Intl.DurationFormat('en', { style: 'short' })
console.log(df.format({ days: 3, hours: 12 }))
// '3 days, 12 hr'Understanding Intl.DurationFormat
The Intl.DurationFormat method in JavaScript creates an Intl.DurationFormat object that enables locale-sensitive duration formatting. It belongs to the Intl object and is one of the most widely used methods for working with intl values in modern JavaScript and TypeScript applications.
The method signature is new Intl.DurationFormat(locales?, options?). It accepts 2 parameters: locales, options. When called, it returns an intl.durationformat object with a format() method. Understanding when and how to use DurationFormat() helps you write more expressive, readable code.
Common use cases for Intl.DurationFormat include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like intl-relativetimeformat, intl-numberformat, intl-datetimeformat, enabling you to chain operations together for complex data manipulation pipelines.
Supported in Chrome 129+, Firefox 131+, Safari 16.4+. Availability may vary.
Browser Compatibility
Supported in Chrome 129+, Firefox 131+, Safari 16.4+. Availability may vary.
Related Methods
Intl.RelativeTimeFormatCreates an Intl.RelativeTimeFormat object that enables language-sensitive relative time formatting
Intl.NumberFormatCreates an Intl.NumberFormat object that enables language-sensitive number formatting
Intl.DateTimeFormatCreates an Intl.DateTimeFormat object that enables language-sensitive date and time formatting
More Intl Methods
Other methods in the Intl object
Related Tools
More Intl Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.