如何使用strptime
或任何其他函数来解析 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"`
如何使用strptime
或任何其他函数来解析 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"`
由?strptime
帮助文件提供(示例更改为您的值):
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
您也可以使用strptime(time[1], "%OSn")
where 0 <= n <= 6,而无需设置digits.secs
.
文档指出“其中哪些受支持取决于操作系统。” 所以YMMV。