How can I parse this date format? Should I change this colon to dot or maybe someone know better solution?
> x <- "2012.01.15 09:00:02:002"
> strptime(x, "%Y.%m.%d %H:%M:%S:%OS")
[1] "2012-01-15 09:00:02"
> strptime(x, "%Y.%m.%d %H:%M:%OS")
[1] "2012-01-15 09:00:02"
> x <- "2012.01.15 09:00:02.002"
> strptime(x, "%Y.%m.%d %H:%M:%OS")
[1] "2012-01-15 09:00:02.001"
There’s a subtle distinction here that may be throwing you off.
As
?strptimenotes:To emphasize that a bit,
%OSrepresents the seconds including fractional seconds — not just the fractional part of the seconds: if the seconds value is 44.234,%OSor%OS3represents 44.234, not .234So the solution is indeed to substitute a
.for that final:.Here’s one way you might do that: