glintl

Format dates and times in many languages, on Erlang and JavaScript.

import glintl
import glintl/locale/en_gb
import gleam/time/duration
import gleam/time/timestamp

let formatter =
  glintl.date_time_formatter(en_gb.locale(), date: glintl.Long, time: glintl.Short)

glintl.format(formatter, timestamp.system_time(), offset: duration.hours(1))
// -> "25 October 2026 at 23:40"

On Erlang the formats come from data baked into this package, made from ICU when the package is built. On JavaScript the runtime’s own Intl.DateTimeFormat is used, so the output can differ slightly between targets and between JavaScript runtimes.

Types

Formats moments in time for one locale and style.

Make one and reuse it: making a formatter does the lookup work once, so formatting is cheap.

pub opaque type Formatter

Locale

opaque

A language and region to format for, such as British English.

Get one from a locale module, like glintl/locale/en_gb, or by tag from glintl/locales.

pub opaque type Locale

How much detail to show, from most to least.

These are the same as the dateStyle and timeStyle options of JavaScript’s Intl.DateTimeFormat. In British English:

StyleDateTime
FullSunday, 25 October 202623:40:58 GMT+01:00
Long25 October 202623:40:58 GMT+1
Medium25 Oct 202623:40:58
Short25/10/202623:40
pub type Style {
  Full
  Long
  Medium
  Short
}

Constructors

  • Full
  • Long
  • Medium
  • Short

Values

pub fn date_formatter(
  locale: Locale,
  style style: Style,
) -> Formatter

Format only the date.

pub fn date_time_formatter(
  locale: Locale,
  date date: Style,
  time time: Style,
) -> Formatter

Format both the date and the time.

pub fn format(
  formatter: Formatter,
  timestamp: timestamp.Timestamp,
  offset offset: duration.Duration,
) -> String

Format a moment in time, as seen from a place offset ahead of UTC.

The offset is rounded down to whole minutes. Time zones are written as a GMT offset, like GMT+1, as glintl knows the offset but not the zone’s name.

pub fn locale_tag(locale: Locale) -> String

The BCP 47 tag of a locale, such as "en-GB".

pub fn time_formatter(
  locale: Locale,
  style style: Style,
) -> Formatter

Format only the time.

✨ Search Document