expression
Chrono-TZ convert UTC to a regional zone
Converting a known UTC instant to a named zone is unambiguous for representable dates. The displayed offset may change with the season. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 2024-01-15T13:00:00+01:00 2024-07-15T14:00:00+02:00 Common mistake: Hardcoding one UTC offset for an entire region throughout the year.
Formal Syntax & Structure
rust syntaxrust
utc.with_timezone(&zone)Working Example
Example Snippetrust
fn main() { use chrono::{TimeZone, Utc}; use chrono_tz::Europe::Paris; for month in [1, 7] { let t = Utc.with_ymd_and_hms(2024, month, 15, 12, 0, 0).single().unwrap(); println!("{}", t.with_timezone(&Paris).to_rfc3339()); }}