timex

Timex - Getting the timezone information from DateTime


I am looking for a way to get the timezone information back from a date time.

iex(13)> t = Timex.now("America/Los_Angeles")
#<DateTime(2016-10-23T12:45:34.697369-07:00 America/Los_Angeles)>
iex(14)> Timex.<given_t_return_timezone>??

Given t, I want back "America/Los_Angeles" again.


Solution

  • I knew it had to be easy. Rather than looking at Timex for this, we can simply do:

    t.time_zone
    

    This is part of Elixir itself since t is a DateTime.