std::time::datetimeDate and time operations.
Work with timestamps as millisecond-precision epoch values. Extract date/time components, format and parse date strings, and perform time arithmetic.
import std::time::datetime;
fn main() {
let now = datetime.now_ms();
let iso = datetime.to_iso8601(now);
println(iso);
let year = datetime.year(now);
println(year);
}
now_msReturn the current time as milliseconds since the Unix epoch.
now_secsReturn the current time as seconds since the Unix epoch.
formatFormat an epoch-millisecond timestamp using a strftime-style format string.
let s = datetime.format(now, "%Y-%m-%d");
parseParse a date string using the given format and return epoch milliseconds.
let ms = datetime.parse("2025-01-15", "%Y-%m-%d");
yearExtract the year component from an epoch-millisecond timestamp.
monthExtract the month (1–12) from an epoch-millisecond timestamp.
dayExtract the day of the month (1–31) from an epoch-millisecond timestamp.
hourExtract the hour (0–23) from an epoch-millisecond timestamp.
minuteExtract the minute (0–59) from an epoch-millisecond timestamp.
secondExtract the second (0–59) from an epoch-millisecond timestamp.
weekdayReturn the day of the week (0 = Monday, 6 = Sunday).
add_daysAdd a number of days to an epoch-millisecond timestamp.
add_hoursAdd a number of hours to an epoch-millisecond timestamp.
diff_secsReturn the difference in seconds between two epoch-millisecond timestamps.
to_iso8601Format an epoch-millisecond timestamp as an ISO 8601 string.
let iso = datetime.to_iso8601(datetime.now_ms());
// e.g. "2025-07-10T14:30:00Z"
now_nanosReturn the current monotonic clock time in nanoseconds.
Uses a monotonic clock not affected by wall-clock adjustments, suitable for high-resolution benchmarking and timing measurements.