std.time
Measures time, and reads and writes dates, times of day and time zones.
The main types are Duration, a span; Instant, a moment on the wall clock in UTC;
Monotonic, a moment on the clock that only moves forward, for how long something takes;
Date, Time and DateTime, the proleptic Gregorian calendar with RFC 3339 text; and Zone,
UTC, a fixed offset or a zone of the time zone database (TZif, RFC 8536). DateTime.format
and DateTime.parseWith use the date patterns of UTS #35. sleep and the timers live in
std.task.
Examples
import std.io { println };
import std.core { ParseError };
import std.time { Date, Duration, TimeError };
fn main(): void throws [TimeError, ParseError] {
let d = try Date.of(2026, 10, 24);
println(d.plusDays(10));
println(try Duration.parse("1h30m"));
println(try Date.parse("2024-02-29"));
}
2026-11-03
1h30m0s
2024-02-29
Types
Instant struct — A moment on the wall clock, in nanoseconds since 1970-01-01T00:00:00Z — POSIX time, no leap seconds counted: the years 1677 to 2262.
Monotonic struct — A moment on the clock that only moves forward: for how long something takes, never for the time of day.
TimeErrorKind enum — The reason for a
TimeError: a value that does not exist; no zone database on the system; a zone the database does not have.TimeError struct — The error for what is no date, no time of day, no offset — February 30th, 24:00, an offset of 90 seconds — or a zone that cannot be loaded, its
kind saying why.Time struct — A time of day: hours 0–23, minutes and seconds 0–59 — no leap second, which POSIX time does not count —, nanoseconds.
Zone struct — A time zone: UTC, a fixed offset, or a zone of the database — its transitions and the rule for the years beyond them (TZif, RFC 8536; a POSIX TZ string).
DateTime struct — A date and a time of day at an offset from UTC: the moment it names, and how it was written.