let date_str = "2020-04-12 22:10:57.000+02";
// convert the string into DateTime<FixedOffset>
let datetime = DateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S%.f%#z").unwrap();
// convert the string into DateTime<Utc> or other timezone
let datetime_utc = datetime.with_timezone(&Utc);
You have to use the custom parser from
str
:Extra info:
%.f
=>.026490
: Similar to.%f
but left-aligned. These all consume the leading dot.%#z
=>+09
: Parsing only: Same as%z
but allows minutes to be missing or present.For more info, see this awnser.