> module
std::datetime
date and time
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
The UTC time secs seconds after the Unix epoch. Err(datetime::Error::InvalidTimestamp) if it is out of range.
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.
> types
A new DateTime n units later, or earlier for a negative n.
A new DateTime n units later, or earlier for a negative n.
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.
A new DateTime n units later, or earlier for a negative n.
A new DateTime n units later, or earlier for a negative n.
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.
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(())
}