LOC-11Recommended
Format dates and numbers for the reader
Format dates, numbers and money for the reader's locale with a formatting library. Show times with a named time zone.
How to do it
Format with an ICU-based library, such as Intl in JavaScript, Babel in Python, the intl extension in PHP or ICU4J in Java. Always pass a locale, and pass a time zone for dates and times. Store and send moments in UTC, as in dates and times, and convert only for display.
Examples
JavaScript example
const when = new Date('2026-03-05T14:00:00Z');
new Intl.DateTimeFormat('sv-SE', { dateStyle: 'long', timeStyle: 'long', timeZone: 'Europe/Stockholm' }).format(when);
// "5 mars 2026 kl. 15:00:00 CET"
new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(1234.5);
// "1.234,50 €", with a no-break space before the €
Python example
# Python with Babel
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
from babel.dates import format_datetime
from babel.numbers import format_currency
when = datetime(2026, 3, 5, 14, 0, tzinfo=timezone.utc)
format_datetime(when, "long", tzinfo=ZoneInfo("Europe/Stockholm"), locale="sv_SE")
# "5 mars 2026 15:00:00 CET"
format_currency(1234.5, "EUR", locale="de_DE") # "1.234,50 €"
PHP example
// PHP with the intl extension
$when = new DateTimeImmutable('2026-03-05T14:00:00Z');
$dates = new IntlDateFormatter('sv_SE', IntlDateFormatter::LONG, IntlDateFormatter::LONG, 'Europe/Stockholm');
echo $dates->format($when); // "5 mars 2026 kl. 15:00:00 CET"
echo (new NumberFormatter('de_DE', NumberFormatter::CURRENCY))->formatCurrency(1234.5, 'EUR'); // "1.234,50 €"
How to check
A unit test formats a fixed date and amount for each supported locale. The output matches the expected strings.
Sources
Related rules
- APP-12 Show times in the user's time zone in Web app interface
- API-7 Send dates as RFC 3339 with a time zone in API design
- LOC-26 Writing date formats by hand in Localization
- LOC-32 Send raw values with standard codes instead of formatted text in Localization
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/localization/dates-numbers-and-text/locale-content">Agent Wranglers localization playbook</a>. In code you write, add a comment next to it with the same link.