Skip to content

TypeScript

Using the Intl Object in TypeScript: An Overview with Examples

I once hard-coded a date format as MM/DD/YYYY and shipped it to European users. They were confused. In most of the world, the month doesn't come first.

6 Jun 2024 · 2 min read

Using the Intl Object in TypeScript: An Overview with Examples

I once hard-coded a date format as MM/DD/YYYY and shipped it to European users. They were confused. In most of the world, the month doesn't come first.

The Intl object solves this. It's built into JavaScript and TypeScript — no libraries needed. It formats numbers, dates, and lists according to the user's locale.

Number formatting

Intl.NumberFormat handles commas, decimals, currencies, and percentages based on locale:

Typescript
const number = 1234567.89;

const usFormatter = new Intl.NumberFormat('en-US');
console.log(usFormatter.format(number)); // "1,234,567.89"

const deFormatter = new Intl.NumberFormat('de-DE');
console.log(deFormatter.format(number)); // "1.234.567,89"

Same number. Different locale. Different output.

Date formatting

Intl.DateTimeFormat formats dates the way each locale expects:

Typescript
const date = new Date('2024-06-06T12:00:00Z');

const formatter = new Intl.DateTimeFormat('en-US', {
  weekday: 'long',
  year: 'numeric',
  month: 'long',
  day: 'numeric',
});

console.log(formatter.format(date)); // "Thursday, June 6, 2024"

Change 'en-US' to 'ja-JP' and you get Japanese date formatting. No string manipulation, no lookup tables.

List formatting

Intl.ListFormat joins arrays into human-readable lists:

Typescript
const items = ['Apple', 'Orange', 'Banana'];

const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
console.log(formatter.format(items)); // "Apple, Orange, and Banana"

In French, that becomes "Apple, Orange et Banana." The Intl object handles the conjunction rules for each language.

The trade-off

Intl is built-in, well-supported, and handles the hard parts of localization automatically. No moment.js, no date-fns for basic formatting.

The cost: browser support for newer APIs like ListFormat and RelativeTimeFormat varies. And Intl only handles formatting — it doesn't handle translations, pluralization rules, or complex i18n workflows. For that, you still need a library like i18next or react-intl.

For formatting numbers and dates? Intl is all you need.

Ehsan Gazar helps software engineers take LLM and agent systems from demo to production. He writes about building LLM systems that hold up in production: evals, tracing, RAG, agent architecture and cost control. He teaches the Senior to Staff AI Engineer cohort on Maven, where engineers learn to design and defend these systems.

Go further
Live cohort on Maven

Forward Deployed AI Engineering: From Customer Problem to Production Value

A live Maven cohort for engineers: 10 live 90-minute sessions taking one AI engagement from customer problem to production, ending with eight artefacts and a working slice in your own repo.

January cohort starts Tue 12 Jan 2027, Tue & Thu 6:30pm London. Enrolling now, 20 seats, $1,800.

View the live cohort

Keep reading