The functions for parsing a string into POSIXct and POSIXlt take similar parameters and return a similar-looking result, but there are differences in how that date-time is stored; see "Remarks."
as.POSIXct("11:38", # time string
format = "%H:%M") # formatting string
## [1] "2016-07-21 11:38:00 CDT"
strptime("11:38", # identical, but makes a POSIXlt object
format = "%H:%M")
## [1] "2016-07-21 11:38:00 CDT"
as.POSIXct("11 AM",
format = "%I %p")
## [1] "2016-07-21 11:00:00 CDT"
Note that date and timezone are imputed.
as.POSIXct("11:38:22", # time string without timezone
format = "%H:%M:%S",
tz = "America/New_York") # set time zone
## [1] "2016-07-21 11:38:22 EDT"
as.POSIXct("2016-07-21 00:00:00",
format = "%F %T") # shortcut tokens for "%Y-%m-%d" and "%H:%M:%S"
See ?strptime
for details on the format strings here.
tz
parameter, the local timezone is used.tz
depend on the location.
CST
is given with "CST6CDT"
or "America/Chicago"
OlsonNames()
system("cat $R_HOME/share/zoneinfo/zone.tab")