Current Time

now / System Time Zone

Julia provides the now() method to retrieve your current system's time as a DateTime. The TimeZones.jl package provides an additional now(::TimeZone) method providing the current time as a ZonedDateTime:

now(tz"Europe/Warsaw")

To get the TimeZone currently specified on you system you can use localzone(). Combining this method with the new now method produces the current system time in the current system's time zone:

now(localzone())

today

Similar to now the TimeZones package also provides a today(::TimeZone) method which allows you to determine the current date as a Date in the specified TimeZone.

julia> a, b = now(tz"Pacific/Midway"), now(tz"Pacific/Apia")(ZonedDateTime(2024, 3, 22, 3, 43, 16, 105, tz"Pacific/Midway"), ZonedDateTime(2024, 3, 23, 4, 43, 16, 105, tz"Pacific/Apia"))
julia> a - b0 milliseconds
julia> today(tz"Pacific/Midway"), today(tz"Pacific/Apia")(Date("2024-03-22"), Date("2024-03-23"))

You should be careful not to use today() when working with ZonedDateTimes as you may end up using the wrong day. For example:

julia> midway, apia = tz"Pacific/Midway", tz"Pacific/Apia"(tz"Pacific/Midway", tz"Pacific/Apia")
julia> ZonedDateTime(today() + Time(11), midway)2024-03-22T11:00:00-11:00
julia> ZonedDateTime(today() + Time(11), apia) # Wrong date; with the current rules apia should be one day ahead of midway2024-03-22T11:00:00+14:00
julia> ZonedDateTime(today(midway) + Time(11), midway)2024-03-22T11:00:00-11:00
julia> ZonedDateTime(today(apia) + Time(11), apia)2024-03-23T11:00:00+14:00

Alternatively, you can use the todayat function which takes care of this for you:

julia> todayat(Time(11), tz"Pacific/Midway")2024-03-22T11:00:00-11:00
julia> todayat(Time(11), tz"Pacific/Apia")2024-03-23T11:00:00+14:00