How to parse milliseconds?

人盡茶涼 提交于 2019-11-26 04:20:02

问题


How do I use strptime or any other functions to parse time stamps with milliseconds in R?

time[1]
# [1] \"2010-01-15 13:55:23.975\"
strptime(time[1], format=\"%Y-%m-%d %H:%M:%S.%f\")
# [1] NA
strptime(time[1], format=\"%Y-%m-%d %H:%M:%S\")
# [1] \"2010-01-15 13:55:23\"`

回答1:


Courtesy of the ?strptime help file (with the example changed to your value):

 z <- strptime("2010-01-15 13:55:23.975", "%Y-%m-%d %H:%M:%OS")
 z # prints without fractional seconds
 op <- options(digits.secs=3)
 z
 options(op) #reset options



回答2:


You can also use strptime(time[1], "%OSn") where 0 <= n <= 6, without having to set digits.secs.



来源:https://stackoverflow.com/questions/2150138/how-to-parse-milliseconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!