JuliaTime / TimeZones.jl

IANA time zone database access for the Julia programming language
Other
86 stars 51 forks source link

How to get UTC Offset as integer #353

Open bryaan opened 2 years ago

bryaan commented 2 years ago

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

omus commented 2 years ago

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.

bryaan commented 2 years ago

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