Working with date and time accessors
If we want to access the individual parts of a date (year, month, day), we can retrieve the various components through the available accessor functions:
julia> earth_day = Date(2018, 4, 22) 2018-04-22 julia>year(earth_day) # the year 2018 julia> month(earth_day) # the month 4
The API also exposes compound methods, for brevity:
julia> monthday(earth_day) # month and day (4, 22) julia> yearmonthday(earth_day) # year month and day (2018, 4, 22)
Similar accessors are available for DateTime
—but no compound methods are provided:
julia> earth_hour = DateTime(2018, 4, 22, 22, 00) 2018-04-22T22:00:00 julia> hour(earth_hour) # the hour 22 julia> minute(earth_hour) # the minute 0
Alternative accessors that return Period
objects are also defined—they have uppercase names:
julia> Hour(earth_hour) # a period of 22 hours 22 hours julia> Month(earth_hour) # a period of 4 months 4 months julia> Month(earth_hour) |>...