expression

Chrono RFC 3339 parsing

RFC 3339 input provides an offset, so it identifies an instant. Normalize to UTC when comparing events across regions; preserve original offset separately if required. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 2025-01-01T22:15:00+00:00 Common mistake: Dropping the offset and keeping the local clock fields unchanged.

Formal Syntax & Structure

rust syntaxrust
DateTime::parse_from_rfc3339(input) -> Result<DateTime<FixedOffset>, ParseError>

Working Example

Example Snippetrust
fn main() {    use chrono::{DateTime, Utc};    let t = DateTime::parse_from_rfc3339("2025-01-02T01:15:00+03:00").unwrap();    println!("{}", t.with_timezone(&Utc).to_rfc3339());}
Rust Reference