Skip to content

formatDate

Module Export

date |> (
locale: text,
format: text|nothing
) => text

Formats a date for display in the given BCP-47 locale, using the locale's own default date pattern.

formatDate renders a date for display. The default is the locale’s own pattern — nothing is baked in — so the same value formats differently per locale: the Swedish short date happens to be ISO (2026-10-10), the US one is 10/10/2026.

Pass a .NET format string as format to take control: custom patterns like 'd MMMM yyyy' or standard specifiers like 'D'.

Examples

The locale’s default pattern

import { formatDate } from 'text'
from 2026-10-10 formatDate ('sv-SE')
// Returns:
// '2026-10-10'
import { formatDate } from 'text'
from 2026-10-10 formatDate ('en-US')
// Returns:
// '10/10/2026'

An explicit format string

import { formatDate } from 'text'
from 2026-10-10 formatDate ('sv-SE', 'd MMMM yyyy')
// Returns:
// '10 oktober 2026'

A culture-neutral explicit format

import { formatDate } from 'text'
from 2026-10-10 formatDate ('', 'yyyy/MM/dd')
// Returns:
// '2026/10/10'

Unresolvable locales fall back to invariant

import { formatDate } from 'text'
from 2026-10-10 formatDate ('xx-BAD')
// Returns:
// '2026-10-10'

Notes

  • Format strings are .NET date format patterns, resolved against the given locale
  • An empty or unresolvable locale uses invariant culture — sensible with explicit format strings that carry no locale-specific letters, as in the 'yyyy/MM/dd' example above