# Converting DateTime from custom time zone to UTC

**URL:** <https://discourse.julialang.org/t/converting-datetime-from-custom-time-zone-to-utc/21181>\
**Category:** General Usage\
**Created:** [February 25, 2019, 6:44pm UTC](https://discourse.julialang.org/t/converting-datetime-from-custom-time-zone-to-utc/21181 "2019-02-25T18:44:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertdj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertdj/32/103_2.png) [@robertdj](https://discourse.julialang.org/u/robertdj)\
**Post date:** [February 25, 2019, 6:44pm UTC](https://discourse.julialang.org/t/converting-datetime-from-custom-time-zone-to-utc/21181/1 "2019-02-25T18:44:51Z")

</div>

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [February 25, 2019, 7:27pm UTC](https://discourse.julialang.org/t/converting-datetime-from-custom-time-zone-to-utc/21181/2 "2019-02-25T19:27:31Z")

</div>

```julia

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

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 25, 2019, 7:43pm UTC](https://discourse.julialang.org/t/converting-datetime-from-custom-time-zone-to-utc/21181/3 "2019-02-25T19:43:44Z")

</div>

Or, slightly briefer:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [February 25, 2019, 7:54pm UTC](https://discourse.julialang.org/t/converting-datetime-from-custom-time-zone-to-utc/21181/4 "2019-02-25T19:54:20Z")

</div>

yes –
