Skip to content
CryoCryo home
Stdlibtime

datetime

import std::time::datetime; · source

Types

DateTime

type struct DateTime {
    year:   i64;
    month:  u32;
    day:    u32;
    hour:   u32;
    minute: u32;
    second: u32;

    static from_unix_secs(secs: i64) -> DateTime;
    static from_system_time(t: &SystemTime) -> DateTime;
    static now() -> DateTime;
    to_string(&this) -> String;
}

A broken-out UTC civil calendar reading, derived from a Unix timestamp or a SystemTime.

import std::time::datetime;

println(f"{DateTime::now()}");     // 2026-07-28T21:14:07Z

All fields are UTC and already normalized: month in 1–12, day in 1–31, hour in 0–23, minute and second in 0–59. year is the proleptic Gregorian year and may be negative for timestamps far before the Common Era. to_string() renders the same ISO-8601 text as the Display impl.

The conversion uses Howard Hinnant's civil_from_days algorithm, which is exact and branch-light across the whole proleptic Gregorian calendar — leap years, century rules, and pre-epoch timestamps all fall out of the arithmetic with no per-month tables. The day index and second-of-day are split with a floor division so a negative timestamp lands on the correct civil day; truncating toward zero would put −1 second on 1970-01-01 instead of 1969-12-31.

Only whole seconds are rendered. Any sub-second precision stays in the source SystemTime.

Properties

PropertyType
yeari64
monthu32
dayu32
houru32
minuteu32
secondu32

Constructors

static from_unix_secs(secs: i64) -> DateTime;

Break a whole-second Unix timestamp into its UTC calendar parts.

static from_system_time(t: &SystemTime) -> DateTime;

The UTC calendar reading for a SystemTime (its whole-second Unix timestamp; any sub-second remainder is dropped).

static now() -> DateTime;

The current UTC date and time from the wall clock.

Methods

to_string(&this) -> String;

Render as ISO-8601 UTC (YYYY-MM-DDThh:mm:ssZ) - the same text as the Display impl, available directly without an f-string.

Trait implementations

implement trait Display for struct DateTime

Constants

const SECS_PER_DAY:  i64 = 86400;
const SECS_PER_HOUR: i64 = 3600;
const SECS_PER_MIN:  i64 = 60;
const DAYS_SHIFT:    i64 = 719468;
const DAYS_PER_ERA:  i64 = 146097;
const YEARS_PER_ERA: i64 = 400;