I have a character format timestamp column that looks like this:
2015-09-24 06:00:00 UTC
2015-09-24 05:00:00 UTC
dateTimeZone <- c("2015-09-24 06:00:00 UTC","2015-09-24 05:00:00 UTC")
I would like to convert this character data to temporary data using POSIXct, and if I knew that all the timestamps were in UTC, I would do it like this:
dateTimeZone <- asPOSIXct(dateTimeZone, tz="UTC")
However, I donβt necessarily know that all timestamps are in UTC, so I tried
dateTimeZone <- asPOSIXct(dateTimeZodateTimeZone, format = "%Y-%m-%d %H:%M:%S %Z")
However, since strptime only supports% Z for output, this returns the following error:
Error in strptime (x, format, tz = tz): using% Z for input is not supported
I checked the documentation for the lubridate package, and I could not see that it handled this problem other than POSIXct.
Is my only option to check the time zone of each row and then use the appropriate time zone with something like the following?
temp[grepl("UTC",datetimezone)] <- as.POSIXct(datetimezone, tz="UTC") temp[grepl("PDT",datetimezone)] <- as.POSIXct(datetimezone, tz="America/Los_Angeles")