xur_

> module

std::datetime

date and time

use std::datetime; feature datetime in the browser

std::datetime provides wall-clock dates and times, backed by chrono. A DateTime is a moment with a fixed offset from UTC; arithmetic keeps that offset and doesn't follow daylight-saving changes. It prints in RFC 3339 form. For measuring durations, see xur.std.time(7).

> functions

# from_timestamp(secs: i64) -> Result<DateTime, Error>

The UTC time secs seconds after the Unix epoch. Err(datetime::Error::InvalidTimestamp) if it is out of range.

# now() -> DateTime

The current time, in the local time zone's current offset.

# parse(text: str, format?: str) -> Result<DateTime, Error>

Without format, parses an RFC 3339 or RFC 2822 string, keeping its offset. With a chrono format string such as "%Y-%m-%d %H:%M:%S", parses a date and time with no offset and takes it as UTC; the format must include both. Err(datetime::Error::Parse) if the text doesn't match.

# utc_now() -> DateTime

The current time in UTC.

> types

┌ type DateTime
# date_time.add_days(n: i64) -> DateTime

A new DateTime n units later, or earlier for a negative n.

# date_time.add_hours(n: i64) -> DateTime

A new DateTime n units later, or earlier for a negative n.

# date_time.add_minutes(n: i64) -> DateTime

A new DateTime n units later, or earlier for a negative n.

# date_time.add_months(n: i64) -> DateTime

A new DateTime n calendar months or years later (earlier for a negative n). A day past the end of the new month becomes its last day, so 31 January plus one month is 28 or 29 February.

# date_time.add_seconds(n: i64) -> DateTime

A new DateTime n units later, or earlier for a negative n.

# date_time.add_weeks(n: i64) -> DateTime

A new DateTime n units later, or earlier for a negative n.

# date_time.add_years(n: i64) -> DateTime

A new DateTime n calendar months or years later (earlier for a negative n). A day past the end of the new month becomes its last day, so 31 January plus one month is 28 or 29 February.

# date_time.day() -> i64

The month (1–12) and day of the month (1–31).

# date_time.format(fmt: str) -> str

Formats with a chrono format string, such as "%Y-%m-%d %H:%M".

# date_time.hour() -> i64

The hour (0–23), minute (0–59) and second (0–59).

# date_time.iso() -> str

The RFC 3339 form, such as 2026-12-02T09:30:00+13:00.

# date_time.minute() -> i64

The hour (0–23), minute (0–59) and second (0–59).

# date_time.month() -> i64

The month (1–12) and day of the month (1–31).

# date_time.second() -> i64

The hour (0–23), minute (0–59) and second (0–59).

# date_time.timestamp() -> i64

Seconds or milliseconds since the Unix epoch.

# date_time.timestamp_millis() -> i64

Seconds or milliseconds since the Unix epoch.

# date_time.weekday() -> str

The day's English name, such as "Monday".

# date_time.year() -> i64

The year.

┌ enum Error

A recoverable datetime error. Match it as `Err(datetime::Error::Parse)` etc.

Error::InvalidTimestamp`from_timestamp`: the seconds value is out of range.
Error::Parse`parse`: the text is not a datetime in the expected format.

> errors

datetime::Error has two variants: InvalidTimestamp and Parse.

> examples

use std::datetime;
use std::io;

fn main() -> Result<()> {
    let now = datetime::now();
    io::println("{}", now.format("%Y-%m-%d %H:%M"));
    io::println("weekday: {}", now.weekday());
    io::println("timestamp: {}", now.timestamp());

    let epoch = datetime::from_timestamp(0)?;
    io::println("epoch: {}", epoch.iso());

    Ok(())
}