What time is it? You can take a peek at the lower right corner of your screen, if you are using windows, or you could open R and type in Sys.time(). Like dates, times are also stored internally as number of seconds since the start of 1970. They are represented by either POSIXlt or POSIXct class. POSIXlt refers to a date stored as a list of nine vectors for year, month, day, hours, minutes, yday, wday, isdst and mday whereas POSIXct is useful for representing time as a numeric vector. It is preferred over the other in terms of storing dates. Let’s look at few examples.
As illustrated you can add and subtract times. R is smart enough to take in account things like timezone and leap years. The function strptime() changes character format provided to a time object using string formats. The argument tz=GMT is to tell R that the time in variable y belongs to Greenwich Mean Time. Also few things to note.
1) Sys.time() is in POSIXct format.
2) POSIXlt allows you to extract things like month, year etc.
3) There are other cool packages for handling dates/times in R like Chron (great if time zone don’t matter!)
4) as.Date() is all about days whereas POSIX is all about seconds.
5) There’s lot more to dates and times!

