I have a column of time stamps in character format 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'd like to convert this character data into time data using POSIXct, and if I knew that all the time stamps were in UTC, I would do it like this:
dateTimeZone <- asPOSIXct(dateTimeZone, tz="UTC")
However, I don't necessarily know that all the time stamps are in UTC, so I tried
dateTimeZone <- asPOSIXct(dateTimeZodateTimeZone, format = "%Y-%m-%d %H:%M:%S %Z")
However, because strptime supports %Z only for output, this returns the following error:
Error in strptime(x, format, tz = tz) :
use of %Z for input is not supported
I checked the documentation for the lubridate package, and I couldn't see that it handled this issue any differently 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")
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…