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
Formatter
opaqueFormats 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
opaqueA 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:
| Style | Date | Time |
|---|---|---|
Full | Sunday, 25 October 2026 | 23:40:58 GMT+01:00 |
Long | 25 October 2026 | 23:40:58 GMT+1 |
Medium | 25 Oct 2026 | 23:40:58 |
Short | 25/10/2026 | 23:40 |
pub type Style {
Full
Long
Medium
Short
}
Constructors
-
Full -
Long -
Medium -
Short
Values
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.