Tz
Time zone support for Elixir.
The Elixir standard library does not ship with a time zone database. As a result, the functions in the DateTime
module can, by default, only operate on datetimes in the UTC time zone. Alternatively (and
deliberately), the standard library relies on
third-party libraries, such as tz
, to bring in time zone support and deal with datetimes in other time zones than UTC.
The tz
library relies on the time zone database maintained by
IANA. As of version 0.3.0, tz
uses version tzdata2019c of the IANA time zone database.
Usage
To use the tz
database, either configure it via configuration:
config :elixir, :time_zone_database, Tz.TimeZoneDatabase
or by calling Calendar.put_time_zone_database/1
:
Calendar.put_time_zone_database(Tz.TimeZoneDatabase)
or by passing the module name Tz.TimeZoneDatabase
directly to the functions that need a time zone database:
DateTime.now("America/Sao_Paulo", Tz.TimeZoneDatabase)
Refer to the DateTime API for more details about handling datetimes with time zones.
Installation
Add tz
for Elixir as a dependency in your mix.exs
file:
def deps do
[
{:tz, "~> 0.3.0"}
]
end
HexDocs
HexDocs documentation can be found at https://hexdocs.pm/tz.