将毫秒时间戳解析为R中的时间 [英] Parsing a Millisecond Timestamp To a Time In R
本文介绍了将毫秒时间戳解析为R中的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经被问过了,但是我找不到确切的答案。
如果我有一个代表午夜以来毫秒的数字,例如34200577,如何将其转换为R时间?
I'm this has been asked before, but I just can't find the exact answer. If I have a number which represents milliseconds since midnight, say 34200577, how do I turn this into an R time?
推荐答案
在午夜构造一个基准时间,添加给定的毫秒数一次转换为秒数并解释为时间:
Construct a 'baseline time' at midnight, add the given millisecond once converted to seconds and interpret as a time:
R> as.POSIXct(as.numeric(ISOdatetime(2013,8,22,0,0,0)) + 34200577/1e3,
+ origin="1970-01-01")
[1] "2013-08-22 09:30:00.576 CDT"
R>
实际上,较短的
R> ISOdatetime(2013,8,22,0,0,0) + 34200577/1e3
[1] "2013-08-22 09:30:00.576 CDT"
R>
以及 ISOdatetime()
的工作原理一个适当的时间对象,它在小数秒内运行,因此我们只应用给定的偏移量。
works as well as ISOdatetime()
returns a proper time object which operates in fractional seconds so we just apply the given offset.
这似乎是正确的
R> 34200577/1e3 # seconds
[1] 34200.6
R> 34200577/1e3/60 # minutes
[1] 570.01
R> 34200577/1e3/60/60 # hours
[1] 9.50016
R>
这篇关于将毫秒时间戳解析为R中的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文