Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Basic Date Parsing In Rust

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