Chrono UTC with offset

Can someone lend me a hand in printing a UTC timestamp with an offset via chrono?

This works:

use chrono::{DateTime, TimeZone, NaiveDateTime, Utc};

fn main() {
    let ts = 1613046735;
    let tz = -21600;
    let time = Utc.timestamp(ts, 0);
    println!("{}", time);

-- Output --
2021-02-11 12:32:15 UTC

I cannot figure out how to adjust the time via the tz offset. Seems like this should be very simple :face_with_raised_eyebrow:

To create one with an offset use:

chrono::FixedOffset::east(tz).timestamp(ts, 0)

To modify the existing offset use:

1 Like

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.