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.floor(rest / 3_600_000);
rest %= 3_600_000;
const minutes = Math.floor(rest / 60_000);
rest %= 60_000;
const seconds = Math.floor(rest / 1000);
const milliseconds = rest % 1000;
return {
hours: sign * hours,
minutes: sign * minutes,
seconds: sign * seconds,
milliseconds: sign * milliseconds,
};
}
const clock = new Intl.DurationFormat("en", {
style: "digital",
hoursDisplay: "auto",
});
// Elapsed: truncate to whole seconds, or any nonzero milliseconds get printed.
export const formatElapsed = (ms) =>
clock.format(splitMs(Math.floor(ms / 1000) * 1000));
// Countdown: round up so the readout reaches 00:00 at the deadline.
export const formatRemaining = (ms) =>
clock.format(splitMs(Math.ceil(ms / 1000) * 1000));
Each line of that helper exists because of one of the points below.
1. It does not carry
Pass { seconds: 125 } and you get 00:125, not 02:05. The formatter prints the fields you give it. That is why splitMs exists. MDN says format() also accepts a Temporal.Duration; I did not try that.
2. Nonzero milliseconds show up uninvited
Feed splitMs(125123) straight in and the readout is 02:05.123. The milliseconds unit is displayed whenever it is nonzero. If your display stops at seconds, cut the value to whole seconds first, as formatElapsed does.
3. It truncates, so choose floor or ceiling on purpose
MDN's constructor page says fractional units are formatted with roundingMode: "trunc", and ECMA-402 sets the same "trunc" rounding mode in its number-formatting steps for these fields. The formatter never rounds up. With fractionalDigits: 0, 2 seconds and 990 ms printed as 0:00:02 for me. For a stopwatch that matches intuition: 1.9 seconds reads 00:01. For a countdown, truncation means the last second reads 00:00 while 0.9 seconds remain. So formatRemaining rounds up before formatting, and formatRemaining(900) returns 00:01. That is my design choice, not a rule from the spec. Pick one convention and use it everywhere, because a readout that flips between the two will look wrong next to the real deadline.
4. Signs must agree, and integers only
MDN: "Each property's value should be an integer, and their signs should be consistent." Both { minutes: 1, seconds: -5 } and { seconds: 1.5 } threw a RangeError for me. The spec's IsValidDuration step is what rejects mixed signs. For overtime, negate every field, which splitMs does: formatRemaining(-1500) gives -00:01.
5. The off-by-one I measured
fractionalDigits accepts 0 to 9. I swept every combination of 60 seconds and 1,000 milliseconds (60,000 inputs, minute zero, en) at 0, 1, 2, and 3 fractional digits, and compared each result with a string built by slicing integer digits.
- Chrome 156: 0 mismatches at every setting.
- Node 24.22.1 (V8 13.6.233.17-node.58): 0 mismatches at 0 and 1 digits, 21 at 2 digits, 396 at 3 digits. Every miss was one low in the last place. One second and 360 ms with two digits printed
1.35.
The spec works with exact mathematical values here and a related validity check carries a note that its sum "cannot be implemented directly using floating-point arithmetic." I can't tell you which engine versions have the problem; I have two data points. If you show hundredths, test your targets, or build the fraction yourself:
import { splitMs } from "./splitMs.js";
export function makeCentiFormatter(locale) {
const clock = new Intl.DurationFormat(locale, {
style: "digital",
hoursDisplay: "auto",
});
const numbers = new Intl.NumberFormat(locale, { minimumIntegerDigits: 2 });
const decimal = new Intl.NumberFormat(locale)
.formatToParts(1.1)
.find((p) => p.type === "decimal").value;
return (ms) => {
const { milliseconds, ...whole } = splitMs(Math.floor(ms / 10) * 10);
const centis = Math.abs(milliseconds) / 10;
return clock.format({ ...whole, milliseconds: 0 }) + decimal + numbers.format(centis);
};
}
I ran the same 60,000-input sweep against this helper on Node 24.22.1 and got 0 mismatches. It also keeps the locale's decimal mark and digits: de printed 00:02,34 for 2,345 ms.
Detect it, and don't test against strings
export const canFormatDurations =
typeof Intl === "object" && typeof Intl.DurationFormat === "function";
When that is false, fall back to padStart. And MDN warns: "You should not compare the results of format() to hardcoded constants." Output can differ between implementations, so my example strings are what I saw, not guarantees. Test your own code on structure instead.
A label for assistive tech
The long style turns { minutes: 1, seconds: 5 } into 1 minute, 5 seconds. That could work as an aria-label you update on start, pause, and finish rather than every tick. That is my suggestion; I did not test it with screen readers.
Sources, all checked on 2026-11-27
- MDN: Intl.DurationFormat
- MDN: Intl.DurationFormat() constructor
- MDN: Intl.DurationFormat.prototype.format()
- ECMA-402: IsValidDuration
Disclosure: I build moment.. It has no signup and runs in 11 languages, and the feature list is a countdown, Pomodoro cycles, repeating intervals, laps, and D-Day dates. The snippets here are standalone examples, not that app's code. A timer like this can only alert you when time is up. The formatting just decides what the number looks like on the way there.
Top comments (1)
The off-by-one sweep is the part that earns this post — 60,000 inputs across two engines, with the mismatches only showing up at 2 and 3 fractional digits on Node and a named ceiling of 1.35 that shrinks with the digit count, is exactly the kind of measurement that turns a docs summary into something I would trust. Two details I will steal: rounding up in formatRemaining so a countdown never reads 00:00 with 0.9 seconds left, and the "long" style as an aria-label updated on start, pause and finish instead of every tick. The one thing I keep wondering about is the 00:02,34 case — when the decimal separator flips by locale, do you keep the fractional part in the visual readout, or strip it there and lean on the aria-label for the precise value?