无法使用R将纪元时间转换为日期

时间:2014-07-07 22:21:29

标签: r epoch

我正在尝试将纪元时间转换为日期。我有一个带有纪元时间的数字数组。

我试过了 -

print(as.POSIXct(x), origin = "1970-01-01", tz = "CST6CDT"))

其中x表示具有纪元时间的数字数组

#Output:
" CDT" " CST" " CDT" " CDT" " CDT" " CST" " CDT" " CST"

我试过这些 -

print(as.POSIXct(1403878908842, origin = "1970-01-01", tz = "CST6CDT"))
print(as.POSIXct(1403878908842, origin = "1970-01-01", tz = ""))

但他们都返回时区而不是转换日期。

1 个答案:

答案 0 :(得分:2)

试试这个:

as.POSIXct(1403878908842/1000, origin = "1970-01-01", tz = "")
## [1] "2014-06-27 10:21:48 EDT"

as.POSIXct(1403878908842/1000, origin = "1970-01-01", tz = "CST6CDT")
## [1] "2014-06-27 09:21:48 CDT"