Adding support for time zones
As previously mentioned, by default, Julia's date/time objects operate in local time, completely ignoring time zones. However, we can easily extend them to become time-zone aware using the TimeZones
package. Please install it in the usual way:
julia> using Pkg pkg> add TimeZones
Once we inform the compiler that we'll be using TimeZones
, a wealth of timezone-related functionalities become available at our fingertips.
We can start by exploring the available time zones:
julia> timezone_names()
439-element Array{AbstractString,1}:
"Africa/Abidjan"
"Africa/Accra"
# output truncated
Let's create a time zone object for Amsterdam
:
julia> amstz = TimeZone("Europe/Amsterdam")
Europe/Amsterdam (UTC+1/UTC+2)
In Julia, a TimeZone
is an abstract type that represents information regarding a specific time zone, which means that it can't be instantiated—we can't create objects of this type. Instead, one of its two subtypes will be automatically used—VariableTimeZone...