Intl in JavaScript
Locale-aware numbers, dates and relative times, built in.
const number = new Intl.NumberFormat("en-GB", {
style: "unit",
unit: "minute",
maximumFractionDigits: 1,
});
console.log(number.format(104.55));
const money = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
});
console.log(money.format(1234.5));
const when = new Intl.DateTimeFormat("en-GB", {
dateStyle: "medium",
timeStyle: "short",
timeZone: "UTC",
});
console.log(when.format(new Date("2026-07-30T09:05:00Z")));
const ago = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
console.log(ago.format(-3, "day"), ago.format(1, "week"));
console.log(new Intl.ListFormat("en").format(["go", "rust", "sql"]));
How it works
- A formatter is reusable and worth keeping.
RelativeTimeFormatwrites phrases like three days ago.ListFormatjoins with the right conjunction.
Keywords and builtins used here
DateIntlconst
The run, in numbers
- Lines
- 24
- Characters to type
- 637
- Tokens
- 179
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 102 seconds.
Step 2 of 2 in URLs & formatting, step 12 of 13 in The browser.