home ~ projects ~ socials

Convert A NaiveDate Time To A DateTime With The Current TimeZone In Rust With chrono

```cargo
[dependencies]
chrono = "0.4.39" 
```

use chrono::{NaiveDate, DateTime};
use chrono::offset::TimeZone;
use chrono::offset::FixedOffset;
use chrono::Local;

fn main() {
  let now = Local::now();

  let dt: DateTime<FixedOffset>= NaiveDate::from_ymd_opt(2024, 5, 29)
    .unwrap()
    .and_hms_opt(0, 0, 0)
    .unwrap()
    .and_local_timezone(TimeZone::from_offset(now.offset()))
    .unwrap();

  dbg!(dt);

}
Output:
[/Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:21:3] dt = 2024-05-29T00:00:00-05:00
-- end of line --