chrono::NaiveDateTime to chrono::DateTime<tz>

Hello

How do you convert chrono::NaiveDateTime to chrono::DateTime<Tz>?

I tried

chrono::DateTime::from_utc(my_naive_datetime.unwrap(), chrono::Utc)

But that yields expected "TzOffset", found "Utc".

NaiveDateTime::and_local_timezone (or NaiveDateTime::and_utc, if you need to use UTC specifically) seems to do what you ask for.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.