home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Basic Date Parsing In Rust

December 2023
Code
//! ```cargo
//! [dependencies]
//! chrono = "0.4.31"
//! ```

use chrono::prelude::*;

fn main() {
  let date_string = "2023-12-21 13:46:47";
  let hour = 3600;
  let tz = FixedOffset::west_opt(5 * hour).unwrap();
  let ndt = NaiveDateTime::parse_from_str(date_string, "%Y-%m-%d %H:%M:%S")
    .unwrap()
    .and_local_timezone(tz)
    .unwrap();
  println!("{}", ndt);
}
Results
2023-12-21 13:46:47 +05:00
═══ § ═══