简体   繁体   English

R-如何使用as.POSIXct将JavaScript时间戳转换为人类日期时间?

[英]R - how to convert JavaScript timestamp to human date time with as.POSIXct?

How can I convert a timestamp in this format to human date? 如何将这种格式的时间戳转换为人类日期?

I create the timestamp using javascript: 我使用javascript创建时间戳:

Date.now();

Output example: 输出示例:

1468833354929

Then I store it in a db. 然后我将其存储在数据库中。

So when I try to convert it with R: 所以当我尝试用R转换它时:

date <- as.POSIXct(1468833354929, origin="1970-01-01", tz="Asia/Singapore")

I get: 我得到:

48515-06-24 09:15:29 SGT

But it should be: 但是应该是:

2016-07-18 09:15:29 SGT

Any ideas why and how I can get the correct human date-time? 有什么想法为什么以及如何获得正确的人类约会时间?

It's in milliseconds. 以毫秒为单位。 Divide by 1000. 除以1000。

R> as.POSIXct(1468833354929/1000, origin="1970-01-01", tz="Asia/Singapore")
[1] "2016-07-18 17:15:54 SGT"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM