struct DateTime
pub struct DateTime :: [Display, Parse]
Conforms to Display, Parse, Equatable.
A date and a time of day at an offset from UTC: the moment it names, and how it was
written. Its text is RFC 3339, 2026-10-08T12:34:56.5+02:00, Z for no offset. Two compare
field by field: the same moment at two offsets is two date-times — toInstant() compares them
as moments.
Methods
pub static fn of(date: Date, time: Time, zone: Zone): DateTime
Returns the date and time in the zone: for a zone of the database, at the offset in force then. A local time that does not exist (the hour a clock springs forward) moves forward by the gap; one that exists twice (the hour it falls back) takes the earlier moment.
pub fn date(): Date
pub fn time(): Time
pub fn offset(): Duration
pub fn zone(): Zone
pub fn plusDays(n: int): DateTime
Returns the same local time n days on, in the zone: across a change of the clocks the
offset follows the zone (a day may be 23 or 25 hours).
pub fn withZone(zone: Zone): DateTime
Returns the same moment in another zone.
pub fn zoneInfo(): ZoneInfo
Returns what the zone says at this moment: the offset, the abbreviation, daylight time.
pub fn format(pattern: string): string throws TimeError
Formats the date and time by a pattern of UTS #35, such as yyyy-MM-dd HH:mm:ss. The
fields: y the year (yy its last two digits, yyyy padded to four), M the month
(MM padded, MMM Jan, MMMM January, MMMMM J), d the day (dd padded), H
the hour of 24 (HH), h of 12 (hh), m the minute, s the second, S… the fraction
to as many digits, a AM/PM, E/EEE Tue, EEEE Tuesday, EEEEE T, Z
+0100 (ZZZZZ +01:00, Z for none), X +01/+0100/+01:00 by its count with Z
for none, x the same without Z; text in '…' as it is, '' a quote; what is no
letter as it is. Names are English.
Errors
Throws TimeError for a pattern letter other than those above, or a malformed pattern.
pub static fn parseWith(
pattern: string,
text: string,
zone: Zone = Zone.utc
): DateTime throws ParseError
Parses a date and time by a pattern of UTS #35, the fields as format writes them: a
number takes as many digits as it finds (a padded field at least its width), a name is
matched without case, a fraction as many digits as there are. What the pattern does not
name is 1970-01-01 00:00:00; without an offset field the zone given decides.
Errors
Throws ParseError with kind Invalid where the pattern is malformed, the text does not
fit it, or the fields name no existing date, time of day or offset.
pub fn toInstant(): Instant
Returns the moment this date-time names.
Panics
Panics with an overflow (RT0002) outside the years an Instant reaches.
pub fn show(): string
pub static fn parse(s: StringView): DateTime throws ParseError
Parses RFC 3339's date-time (§5.6), strictly: T or t between the date and the time, a
fraction of any length — cut to nanoseconds —, Z, z or ±hh:mm; no space for the T,
no second 60.
Errors
Throws ParseError with kind Empty for an empty text and Invalid for a text of another
shape or a date or time that does not exist.
fn equals(o: DateTime): bool