-
I am migrating from In my code, I need to convert use std::time::SystemTime;
mod use_chrono {
use super::*;
use chrono::prelude::*;
pub fn system_time_to_local_time(system_time: &SystemTime) -> DateTime<Local> {
(*system_time).into()
}
}
mod use_time {
use super::*;
pub fn system_time_to_local_time(system_time: &SystemTime) -> ??? {
???
}
}
fn main() {
let now = SystemTime::now();
let local_time = use_chrono::system_time_to_local_time(&now);
println!("local_time (chrono): {}", local_time);
let local_time = use_time::system_time_to_local_time(&now);
println!("local_time (time): {}", local_time);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You should be able to do this (I haven't checked it): let mut odt: OffsetDateTime = system_time.into();
let offset = UtcOffset::local_offset_at(odt)?;
odt = odt.to_offset(offset); Keep in mind that the second line will fail if any of the following is true:
I had never considered adding an |
Beta Was this translation helpful? Give feedback.
You should be able to do this (I haven't checked it):
Keep in mind that the second line will fail if any of the following is true:
num_threads
crate does not support the operating system, resulting in whether the program is multithreaded unknowableI had never considered adding an
OffsetDateTime::to_local_offset(self) -> Result<Self, error:IndeterminateOffset>
method, but I could certainly see the utility. I will look into whether this makes sense and would be suffici…