std.time

Time: the current date and time in UTC, measuring durations, and waiting.

import std.time

print(time.now().iso())          // 2026-10-15T08:30:01.123Z
let start: i64 = time.millis()
time.sleep(250)
print(time.millis() - start)     // about 250

Types

struct Time

pub struct Time {
    pub unix_millis: i64,
}

A moment, as milliseconds since 1970-01-01T00:00:00Z.

Methods

pub fn unix_seconds(self) -> i64
pub fn add_millis(self, millis: i64) -> Time
pub fn add_seconds(self, seconds: i64) -> Time
pub fn parts(self) -> DateTime

The year, month, day and so on, in UTC.

pub fn date(self) -> string

The date, as in 2026-10-15.

pub fn iso(self) -> string

ISO 8601 in UTC, with milliseconds: 2026-10-15T08:30:01.123Z.

pub fn http_date(self) -> string

The format of HTTP headers: Thu, 15 Oct 2026 08:30:01 GMT.

struct DateTime

pub struct DateTime {
    pub year: i64,
    pub month: i64,
    pub day: i64,
    pub hour: i64,
    pub minute: i64,
    pub second: i64,
    pub millisecond: i64,
    pub weekday: i64,
}

The parts of a moment in UTC.

month

1 to 12.

day

1 to 31.

weekday

1 (Monday) to 7 (Sunday).

Functions

fn now

pub fn now() -> Time

The current time, from the system clock.

fn from_unix_millis

pub fn from_unix_millis(millis: i64) -> Time

fn from_unix_seconds

pub fn from_unix_seconds(seconds: i64) -> Time

fn millis

pub fn millis() -> i64

Milliseconds on a clock that only moves forward, for measuring how long something takes. Unlike now, it does not jump when the system clock is set.

fn sleep

pub fn sleep(millis: i64)

Waits this many milliseconds.