typestar

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

  1. A formatter is reusable and worth keeping.
  2. RelativeTimeFormat writes phrases like three days ago.
  3. ListFormat joins with the right conjunction.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 2 in URLs & formatting, step 12 of 13 in The browser.

← Previous Next →