How to convert a string to chrono::datetime::DateTime in Rust

1 Answer

0 votes
use chrono::{Utc, DateTime};

fn main() {
    let now = Utc::now();
    
    let str_dt: String = format!("{}", now);
    
    let dt: DateTime<Utc> = str_dt.parse().unwrap();
    
    println!("{}", dt);
}


    
/*
run:
 
2024-08-12 08:25:10.034387984 UTC
 
*/

 



answered Aug 12, 2024 by avibootz
...