Module format

Formatting (and parsing) utilities for date and time.

This module provides the common types and routines to implement, for example, DateTime::format or DateTime::parse_from_str methods. For most cases you should use these high-level interfaces.

Internally the formatting and parsing shares the same abstract formatting items, which are just an Iterator of the Item type. They are generated from more readable format strings; currently Chrono supports a built-in syntax closely resembling C's strftime format. The available options can be found here.

Example

# #[cfg(feature = "alloc")] {
use chrono::{NaiveDateTime, TimeZone, Utc};

let date_time = Utc.with_ymd_and_hms(2020, 11, 10, 0, 1, 32).unwrap();

let formatted = format!("{}", date_time.format("%Y-%m-%d %H:%M:%S"));
assert_eq!(formatted, "2020-11-10 00:01:32");

let parsed = NaiveDateTime::parse_from_str(&formatted, "%Y-%m-%d %H:%M:%S")?.and_utc();
assert_eq!(parsed, date_time);
# }
# Ok::<(), chrono::ParseError>(())

Modules

Structs

Enums

Type Aliases