Converts a duration in milliseconds to a human-readable string such as
"1d 4h 32m 10s 250ms".
Milliseconds are shown as their own integer component; fractional inputs
are rounded to the nearest millisecond. Any zero-valued components are
omitted from the formatted output, so a zero-millisecond input produces an
empty string. Negative durations are formatted from their magnitude and
prefixed with "-" (e.g. -90_000 → "-1m 30s").
Parameters
ms: number
Duration in milliseconds. Must be a finite number.
locale: string = "en"
BCP 47 locale tag passed to Intl.DurationFormat. Defaults
to "en".
Returns string
A formatted duration string.
Throws
If ms is not finite (NaN, Infinity, -Infinity)
or locale is not a valid BCP 47 language tag.
Converts a duration in milliseconds to a human-readable string such as
"1d 4h 32m 10s 250ms".Milliseconds are shown as their own integer component; fractional inputs are rounded to the nearest millisecond. Any zero-valued components are omitted from the formatted output, so a zero-millisecond input produces an empty string. Negative durations are formatted from their magnitude and prefixed with
"-"(e.g.-90_000→"-1m 30s").