expression
time crate OffsetDateTime conversion
Convert a timestamp to a different fixed offset without changing the instant. A fixed offset does not include regional transition rules. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 2 0 Common mistake: Replacing the offset when the desired operation is preserving the instant.
Formal Syntax & Structure
rust syntaxrust
OffsetDateTime::from_unix_timestamp(i64); to_offset(UtcOffset)Working Example
Example Snippetrust
fn main() { use time::{OffsetDateTime, UtcOffset}; let utc = OffsetDateTime::from_unix_timestamp(0).unwrap(); let local = utc.to_offset(UtcOffset::from_hms(2, 0, 0).unwrap()); println!("{} {}", local.hour(), local.unix_timestamp());}