How to get hour from Offset? #81
-
Hi, I wanted to port this Chrono code to Jiff equivalent. fn main() {
let offset_second = chrono::Local::now().offset().local_minus_utc();
let offset_hour = chrono::Duration::seconds(offset_second.into()).num_hours();
dbg!(&offset_hour);
let offset_hour: jiff::tz::Offset = jiff::Zoned::now().offset();
dbg!(&offset_hour);
} Thanks for JIff! 🥞 |
Beta Was this translation helpful? Give feedback.
Answered by
BurntSushi
Aug 7, 2024
Replies: 1 comment 1 reply
-
We can consider adding |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
azzamsa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
offset.seconds() / (60 * 60)
should do the trick.We can consider adding
offset.hours()
andoffset.minutes()
methods to make this easier. But I'm curious, what are you trying to do with the hours from an offset? (And specifically, this would ignore any minute or second component, since an offset isn't necessarily a whole number of hours.)