1. What about times?
So far we've been talking just about dates, but what about times? Yes, R also has built-in objects for handling dates with times, something we'll call datetimes
2. ISO 8601
ISO 8601 also has something to say about datetimes. Just like dates, if you have an accompanying time it should be written from largest unit to smallest unit using a fixed number of digits and optionally separating the units with a colon. When combined with a date, the time is sometimes prefixed with the character T.
3. Datetimes in R
There are two built in types of objects for datetimes in R, POSIXlt and POSIXct. POSIXlt stores a date in a list with components for each unit, whereas POSIXct stores the date as the number of seconds since the beginning of 1970. Because of its simpler structure POSIXct is more amenable to being stored in data frames and the one we'll focus on exclusively.
Just like Date objects, there is a function to take a string and turn into a POSIXct object. And perhaps unsurprisingly it's called as (dot) POSIXct. And, also just like dates, as (dot) POSIXct will read in ISO 8601 datetimes, but anything else will need to be parsed specially, something you'll master in Chapter 2.
4. Timezones
ISO 8601 also allows the specification of a timezone. If no time zone is specified it is assumed to be local time.
The suffix on a time of Z, denotes a time in the UTC time zone. UTC is short for Coordinated Universal Time, an international standard which doesn't observe daylight savings.
Other timezones are specified in ISO 8601 as offsets from this timezone. Unfortunately as (dot) POSIXct won't recognize the ISO 8601 specification of timezones, it will assume the local timezone, unless you set another one with the tz argument. You'll learn more about timezones in Chapter 4.
5. Datetimes behave nicely too
Once you've got datetimes in R, they behave nicely, just like dates. You can compare datetimes, subtract datetimes and plot datetimes.
6. Let's practice!
You'll try all these things in the following exercises.