如何解析此日期格式?我应该将此冒号更改为点,还是应该有人知道更好的解决方案?
> 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"
最佳答案
这里有一个微妙的区别,可能会让您失望。
如?strptime
所述:
for 'strptime' '%OS' will input seconds including fractional seconds.
为了强调这一点,
%OS
代表秒,包括分数秒---不只是秒的部分:如果秒值为44.234,则%OS
或%OS3
代表44.234,而不是.234因此,解决方案的确是用
.
代替最终的:
。这是您可以执行此操作的一种方法:
x <- "2012.01.15 09:00:02:002"
strptime(gsub(":", ".", x), "%Y.%m.%d %H.%M.%OS")
关于r - 日期格式的冒号,介于秒和毫秒之间。如何解析R?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13613655/