Skip to content

Timezone at specified time #99

Answered by Kijewski
Sytten asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Émile! So, you want to project a timestamp into the local time zone? Then tz::UtcDateTime::project() and/or tz::DateTime::project() should be what you are looking for:

let tz = tzdb::local_tz().unwrap();
let utc_ts = tz::UtcDateTime::new(2022, 8, 8, 14, 49, 33, 369777135).unwrap();
let local_ts = utc_ts.project(tz).unwrap();
dbg!(
    // "2022-08-08T14:49:33.369777135Z"
    utc_ts.to_string(),
    // "2022-08-08T16:49:33.369777135+02:00"
    local_ts.to_string(),
    // "CEST"
    local_ts.local_time_type().time_zone_designation(),
    // 7200
    local_ts.local_time_type().ut_offset(),
);

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Sytten
Comment options

Answer selected by Sytten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants