The extra T and Z are throwing me off:
strptime("2017-06-08T11:55:53.179000Z", "%Y-%m-%dT%H:%M:%SZ")
Returns NA
The extra T and Z are throwing me off:
strptime("2017-06-08T11:55:53.179000Z", "%Y-%m-%dT%H:%M:%SZ")
Returns NA
Just use the anytime()
function of the anytime package:
R> anytime("2017-06-08T11:55:53.179000Z")
[1] "2017-06-08 11:55:53.178 CDT"
R>
The whole point of the anytime package is to parse such common formats without requiring a format. Dealing with the trailing Z
comes for free via the Boost parser.
If you want it interpreted as UTC use the corresponding utctime()
package:
R> utctime("2017-06-08T11:55:53.179000Z")
[1] "2017-06-08 06:55:53.178 CDT"
R>
If you want it stored as UTC, set the timezone accordingly:
R> utctime("2017-06-08T11:55:53.179000Z", tz="UTC")
[1] "2017-06-08 11:55:53.178 UTC"
R>
According to ?strptime
, you can parse it with %OS
parameter by setting the digits.secs
option:
Specific to R is %OSn, which for output gives the seconds truncated to 0 <= n <= 6 decimal places (and if %OS is not followed by a digit, it uses the setting of getOption("digits.secs"), or if that is unset, n = 0). Further, for strptime %OS will input seconds including fractional seconds. Note that %S does not read fractional parts on output.
options(digits.secs = 6)
strptime("2017-06-08T11:55:53.179000Z", "%Y-%m-%dT%H:%M:%OSZ")
# [1] "2017-06-08 11:55:53.179 EDT"