Reputation: 117
I'm working with a date format of YYYY-mm-ddTHH:MM:SS.000Z (2014-02-05T08:45:01.326Z) or that has a separator T that separates the date from the time, and time indicator Z or "Zulu time" (UTC). I'm trying to store the timestamp as a class POSIXct using the following function:
timestamp <- as.POSIXct(strptime(as.character(data$Time), tz = "UTC", "%Y-%m-%d %H:%M:%S"))
at the moment I'm getting NA's. If anyone has some advice on how I can incorporate the 'T' and 'Z' indicators in my conversion I will highly appreciate it.
Upvotes: 6
Views: 2630
Reputation: 18500
You can include the characters in your format string:
d <- "2014-02-05T08:45:01.326Z"
timestamp <- strptime(d, tz = "UTC", "%Y-%m-%dT%H:%M:%OSZ")
Note that here %OS
is used instead of %S
because you have fractional seconds.
Upvotes: 10