Menu

1 / 2

Formatting Timer Readouts with Intl.DurationFormat: What It Does and What It Leaves to You

DEV Community: frontend·Nomad Wozo·3 days ago
#wBNIgcLc
#devtofrontend#devto#dev#seconds#intl
Long article (1179 words) — no AI summary yet.
Reading 0:00
15s threshold

Most timer readouts are built from padStart(2, "0") and a colon. That works until you want localized digits, or a spoken-friendly string like "25 minutes". Intl.DurationFormat covers both, and MDN labels it Baseline 2025: "Since March 2025, this feature works across the latest devices and browser versions."

I tried it on a timer readout and found four places where it does less than you might assume, plus one engine difference I measured. Everything below ran on Node 24.22.1 and desktop Chrome 156 on Linux. I did not test Firefox or Safari, and I only used the en locale unless noted.

The basic readout

The digital style prints 1:50:00 -style output. With only style: "digital" , five seconds comes out as 0:00:05 . Adding hoursDisplay: "auto" hides the hours until they are nonzero: 00:05 , then 1:00:03 .

export function splitMs ( totalMs ) { const sign = totalMs < 0 ? - 1 : 1 ; let rest = Math . abs ( Math . trunc ( totalMs ) ) ; const hours = Math .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.