如何在R中转换unix时间戳(毫秒)和时区? [英] How to convert unix timestamp (milliseconds) and timezone in R?

查看:2843
本文介绍了如何在R中转换unix时间戳(毫秒)和时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据,它们有两列具有事件时间戳的列 time timezone 例如:

 时间时区
1433848856453 10800000

似乎时间戳信息中也有小数秒。我不明白时区格式,但它必须是一个等效的unix格式。我还需要保留小数秒。我该怎么做,就像R那样呢?

  2015-01-01 13:34:56.45 UTC 

注意:此可读取日期不是显示的unix时间戳的实际转换值。

解决方案

看起来像 timezone 列是时区偏移量,以毫秒为单位。我认为这意味着时区列将手动调整为夏令时



所以你应该添加时间 timezone 列转换为 POSIXct 。您还应该将 tz 设置为UTC,否则不会对您的 POSIXct 对象。

  R>时间<  -  1433848856453 
R>时区< - 10800000
R> options(digits.secs = 3)
R> .POSIXct((time + timezone)/ 1000,tz =UTC)
[1]2015-06-09 14:20:56.453 UTC
pre>

I have data which has two columns time and timezone 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 manually

So you should add the time and timezone columns before converting to POSIXct. You should also set the tz to "UTC" so no DST adjustments will be made to your POSIXct 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆