1.4 Date and time

Dates are standardized in the format YYYY-MM-DD (ISO-8601), and when contain time are of the form YYYY-MM-DD HH:MM:SS. This procedure facilitates the programming and organization of the material, ensuring that the files named in this way are ordered chronologically in any system. The lubridate (Grolemund and Wickham 2011) package provides a number of useful functions for dealing with temporal elements.

library(lubridate)
# Apollo 11 lands on the Moon on July 20, 1969 at 20:17 UTC (Coordinated Universal Time)
(apollo11 <- ymd_hms('1969-07-20 20:17:00'))
## [1] "1969-07-20 20:17:00 UTC"
year(apollo11)    # year
## [1] 1969
month(apollo11)   # month
## [1] 7
day(apollo11)     # day
## [1] 20
hour(apollo11)    # hour
## [1] 20
minute(apollo11)  # minute
## [1] 17
second(apollo11)  # second
## [1] 0
wday(apollo11, label = TRUE)  # week day
## [1] Sun
## Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
with_tz(apollo11, 'America/Sao_Paulo') # São Paulo/Brasília time
## [1] "1969-07-20 17:17:00 -03"
now()-apollo11 # number of days from apollo11 landing to the closing of this material
## Time difference of 19849.7 days

References

Grolemund, Garrett, and Hadley Wickham. 2011. “Dates and Times Made Easy with lubridate.” Journal of Statistical Software 40 (3): 1–25. https://www.jstatsoft.org/v40/i03/.