Converting DateTime from custom time zone to UTC

With the TimeZones package I can make a ZonedDateTime that has information about my timezone:

t = ZonedDateTime(2019, 2, 25, 12, 34, 56, localzone())

I am in Central European Time so the above command returns 2019-02-25T12:34:56+01:00 on my computer.

This corresponds to the UTC time that is an hour earlier, that is, 2019-02-25T11:34:56.

Is there a nice way convert such a ZonedDateTime to (Zoned)DateTime with the equivalent UTC time?


julia> UT = timezones_from_abbr("UTC")[1];

julia> t = ZonedDateTime(2019, 2, 25, 12, 34, 56, localzone())
2019-02-25T12:34:56-05:00

julia> astimezone(t, UT)
2019-02-25T17:34:56+00:00

and see next

Or, slightly briefer:

julia> t = ZonedDateTime(2019, 2, 25, 12, 34, 56, localzone())
2019-02-25T12:34:56+01:00

julia> astimezone(t, tz"UTC")
2019-02-25T11:34:56+00:00
1 Like

yes –