简体   繁体   English

R时区GMT和CET转换Unix时间戳

[英]R timezone GMT and CET convert unix timestamp

I got a unix timestamp from a GMT-based database wich i want to convert to datetime format. 我从基于GMT的数据库中获得了unix时间戳,我想将其转换为日期时间格式。 I use R in Germany. 我在德国使用R。 Unix timestamp from GMT-based database: 1525732148 来自基于GMT的数据库的Unix时间戳:1525732148

I convert it with: 我将其转换为:

install.packages("anytime")
library(anytime)
anytime(as.numeric(as.character(1525732148)))

Why do i get same date time, independet of system-date? 为什么我得到相同的日期时间,与系统日期无关?

anytime(as.numeric(as.character(1525732148, tz="GMT")))
anytime(as.numeric(as.character(1525732148, tz="CET")))

Both give me as result: "2018-05-07 22:29:08 UTC" 两者都给我结果:“ 2018-05-07 22:29:08 UTC”

I expected different results, because of different timezones. 由于时区不同,我预期会有不同的结果。

The problem is as follows: 问题如下:

> as.character(1525732148, tz="GMT")
[1] "1525732148"

This is what anytime gets as input. 这就是anytime获得的输入。 The tz parameter is supposed to be passed to anytime , not to as.character , which swallows without warning any additional parameters it does not recognise. tz参数应该被传递给anytime ,而不是as.character ,它会吞咽而不会警告它无法识别的任何其他参数。 Try anytime(1525732148, tz="GMT") . anytime(1525732148, tz="GMT")尝试anytime(1525732148, tz="GMT")

> anytime::anytime(1525732148, tz="GMT")
[1] "2018-05-07 22:29:08 GMT"
> anytime::anytime(1525732148, tz="CET")
[1] "2018-05-08 00:29:08 CEST"

See: anytime 查看: anytime

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

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