Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ format(duration)
### Parameters

- `duration`
- : The duration object to be formatted. It should include some or all of the following properties: `"months"`, `"weeks"`, `"days"`, `"hours"`, `"minutes"`, `"seconds"`, `"milliseconds"`, `"microseconds"`, `"nanoseconds"`.
- : The duration object to be formatted. It should include some or all of the following properties: `months`, `weeks`, `days`, `hours`, `minutes`, `seconds`, `milliseconds`, `microseconds`, `nanoseconds`.

## Examples

### Using format with an object as parameter
### Using format()

The following example shows how to create a Duration formatter using the English language.

```js
const duration = {
Expand Down Expand Up @@ -77,29 +79,37 @@ new Intl.DurationFormat("pt", { style: "narrow" }).format(duration);
// With style set to "digital" and locale set to "en"
new Intl.DurationFormat("en", { style: "digital" }).format(duration);
// "1:46:40"
```

### Using format with fractionalDigits option
// With style set to "digital", locale set to "en", and hours set to "long"
new Intl.DurationFormat("en", { style: "digital", hours: "long" }).format(
duration,
);
// "1 hour, 46:40"
```

Use the `format` getter function for formatting using with fractionalDigits options and setting milliseconds display to `narrow`.
### Using format() with the fractionalDigits option

```js
const duration = {
hours: 11,
minutes: 30,
seconds: 12,
milliseconds: 345,
microseconds: 600,
};

// Example using fractionalDigits
new Intl.DurationFormat("en", { fractionalDigits: 2 }).format(duration);
// => 12 sec, 345 ms, 600 μs
new Intl.DurationFormat("en", { style: "digital" }).format(duration);
// "11:30:12.3456"

new Intl.DurationFormat("en", { style: "digital", fractionalDigits: 5 }).format(
duration,
);
// "11:30:12.34560"

// Example using fractionalDigits and milliseconds set to `long`
new Intl.DurationFormat("en", {
milliseconds: "long",
fractionalDigits: 2,
}).format(duration);
// => 12 sec, 345 milliseconds, 600 μs
new Intl.DurationFormat("en", { style: "digital", fractionalDigits: 3 }).format(
duration,
);
// "11:30:12.346"
```

## Specifications
Expand Down