Skip to content

formatInstant

Module Export

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

Formats an instant for display in the given BCP-47 locale, using the locale's own default date-and-time pattern.

formatInstant renders an instant for display, preserving the stored offset. The default is the locale’s own pattern (its general date-and-time pattern) — nothing is baked in.

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

Examples

The locale’s default pattern

import { formatInstant } from 'text'
from 2026-10-10T14:30:00Z formatInstant ('sv-SE')
// Returns:
// '2026-10-10 14:30'
import { formatInstant } from 'text'
from 2026-10-10T14:30:00Z formatInstant ('en-US')
// Returns:
// '10/10/2026 2:30 PM'

An explicit format string

import { formatInstant } from 'text'
from 2026-10-10T14:30:00Z formatInstant ('sv-SE', 'd MMMM yyyy HH:mm')
// Returns:
// '10 oktober 2026 14:30'

Unresolvable locales fall back to invariant

import { formatInstant } from 'text'
from 2026-10-10T14:30:00Z formatInstant ('xx-BAD')
// Returns:
// '2026-10-10T14:30:00.0000000Z'

Notes

  • Format strings are .NET date/time format patterns, resolved against the given locale
  • The invariant fallback is the ISO 8601 form — the code-compatible default