如何在R中转换unix时间戳(毫秒)和时区? [英] How to convert unix timestamp (milliseconds) and timezone in R?
问题描述
我有两个数据,它们有两列具有事件时间戳的列 time
和 timezone
例如:
时间时区
1433848856453 10800000
似乎时间戳信息中也有小数秒。我不明白时区格式,但它必须是一个等效的unix格式。我还需要保留小数秒。我该怎么做,就像R那样呢?
2015-01-01 13:34:56.45 UTC
注意:此可读取日期不是显示的unix时间戳的实际转换值。
看起来像 timezone
列是时区偏移量,以毫秒为单位。我认为这意味着时区列将手动调整为夏令时
所以你应该添加时间
和 timezone
列转换为 POSIXct
。您还应该将 tz
设置为UTC
,否则不会对您的 POSIXct
对象。
R>时间< - 1433848856453
pre>
R>时区< - 10800000
R> options(digits.secs = 3)
R> .POSIXct((time + timezone)/ 1000,tz =UTC)
[1]2015-06-09 14:20:56.453 UTC
I have data which has two columns
time
andtimezone
that have the timestamp of events. Examples are:time timezone 1433848856453 10800000
It seems like the timestamp has fractional seconds in the information as well. I don't understand the timezone format but it must be an equivalent unix format. I need to preserve the fractional seconds as well. How do I go from that to something like in R?
2015-01-01 13:34:56.45 UTC
Note: This human readable date is not the actual converted values of the unix timestamp shown.
解决方案It looks like the
timezone
column is the timezone offset, in milliseconds. I assume that means the timezone column will adjust for daylight saving time manuallySo you should add the
time
andtimezone
columns before converting toPOSIXct
. You should also set thetz
to"UTC"
so no DST adjustments will be made to yourPOSIXct
object.R> time <- 1433848856453 R> timezone <- 10800000 R> options(digits.secs=3) R> .POSIXct((time+timezone)/1000, tz="UTC") [1] "2015-06-09 14:20:56.453 UTC"
这篇关于如何在R中转换unix时间戳(毫秒)和时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!