任何人都可以识别此表格进行日期存储吗?

时间:2019-04-18 17:30:58

标签: r time

在此之前,我具有来自JSON Blob和Excel的值。

timestamp的字段中包含类似这样的值

timestamp = [
1519383511397, 1536864135321,
1540584502333, 1535641486675,
1541126656968, 1544634450352,
1538790352678, 1538171618112,
1546300725869, 1542642909566
]

我尝试用as.POSIXct(as.numeric(1519383511397), origin = "1970-01-01")进行转换。那没用。我尝试了其他一些变体,例如将开始年份设置为0-01-012000-01-01

您能识别这种格式吗?有没有更好的方法来解析它们?

2 个答案:

答案 0 :(得分:2)

这看起来像一个Unix EPOCH13时间戳,以毫秒为单位,除以1000,得出以下假设的unix时间:

timestamp  <-  c(
  1519383511397, 1536864135321,
  1540584502333, 1535641486675,
  1541126656968, 1544634450352,
  1538790352678, 1538171618112,
  1546300725869, 1542642909566
  )

as.POSIXct(timestamp/1000,origin="1970-01-01")

[1] "2018-02-23 11:58:31 CET"  "2018-09-13 20:42:15 CEST" "2018-10-26 22:08:22 CEST" "2018-08-30 17:04:46 CEST" "2018-11-02 03:44:16 CET" 
 [6] "2018-12-12 18:07:30 CET"  "2018-10-06 03:45:52 CEST" "2018-09-28 23:53:38 CEST" "2019-01-01 00:58:45 CET"  "2018-11-19 16:55:09 CET"

答案 1 :(得分:1)

我的猜测是,以毫秒为单位的javascript时间可以轻松转换。

timestamp = c(
  1519383511397, 1536864135321,
  1540584502333, 1535641486675,
  1541126656968, 1544634450352,
  1538790352678, 1538171618112,
  1546300725869, 1542642909566
  )

conv_ms <- as.Date(timestamp / (24 * 60 * 60 * 1000), origin = as.Date("1970-01-01"))

R> conv_ms
 [1] "2018-02-23" "2018-09-13" "2018-10-26" "2018-08-30" "2018-11-02" "2018-12-12" "2018-10-06" "2018-09-28"
 [9] "2018-12-31" "2018-11-19"