TimeZones.jl icon indicating copy to clipboard operation
TimeZones.jl copied to clipboard

How to get UTC Offset as integer

Open bryaan opened this issue 4 years ago • 6 comments

How can I get the current UTC offset from tz"America/New_York" ?

bryaan avatar Jul 23 '21 02:07 bryaan

You can use access the offset of a specific ZonedDateTime via:

julia> using TimeZones

julia> now(tz"America/New_York").zone.offset
UTC-5/+1

julia> string(ans)
"-04:00"

If this is something you're just wanting to view for yourself you can do:

julia> show_next_transition(tz"America/New_York")
Transition Date:   2021-11-07
Local Time Change: 02:00 → 01:00 (Backward)
Offset Change:     UTC-5/+1 → UTC-5/+0
Transition From:   2021-11-07T01:59:59.999-04:00 (EDT)
Transition To:     2021-11-07T01:00:00.000-05:00 (EST)

Which shows the current offset in "Offset Change" as well as a other information.

omus avatar Jul 23 '21 16:07 omus

@omus Thank you! Can we add an int(timezoneawaretime) to make integer conversion easier?

bryaan avatar Jul 25 '21 21:07 bryaan