当前位置: 动力学知识库 > 问答 > 编程问答 >

convert string to time in r

问题描述:

I have an array of time strings, for example 115521.45 which corresponds to 11:55:21.45 in terms of an actual clock.

I have another array of time strings in the standard format (HH:MM:SS.0) and I need to compare the two.

I can't find any way to convert the original time format into something useable.

I've tried using strptime but all it does is add a date (the wrong date) and get rid of time decimal places. I don't care about the date and I need the decimal places:

for example

t <- strptime(105748.35, '%H%M%OS') = ... 10:57:48

using %OSn (n = 1,2 etc) gives NA.

Alternatively, is there a way to convert a time such as 10:57:48 to 105748?

网友答案:

Set the options to allow digits in seconds, and then add the date you wish before converting (so that the start date is meaningful).

options(digits.secs=3)

strptime(paste0('2013-01-01 ',105748.35), '%Y-%M-%d %H%M%OS')
分享给朋友:
您可能感兴趣的文章:
随机阅读: