use chrono::{DateTime, TimeZone, Utc};
use chrono_tz::{Europe::Paris, Tz};
fn main() {
let current_time = Utc::now();
let paris_time: DateTime = current_time.with_timezone(&Paris);
println!("{}", paris_time.format("%Y-%m-%d %H:%M:%S%.f %z %Z"));
}
As-Is:
2023-05-16 16:11:56.483770 +0200 CEST
Should-be:
2023-05-16 16:11:56.483770 +0200 CEST Europe::Paris
hax10
May 16, 2023, 2:40pm
2
According to the chrono crate documentation , %Z
in your formatted string will return an acronym like CEST, not a complete description like Europe/Paris. If you want this, you can use:
println!("{} {}", paris_time.format(...), Paris.to_string());
system
Closed
August 14, 2023, 2:41pm
3
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.