Character POSIXct Conversion in R causes wrong timezone values on daylight saving time transition (CEST/CET))

只谈情不闲聊 提交于 2019-11-27 20:37:40

Here's a work around that goes from POSIXct to character back to POSIXct preserving the original daylight savings time status.

Sys.setenv(TZ='Europe/Berlin') # to reproduce OP's example
time_seq_01 <- seq(as.POSIXct("2012-10-28 02:00:00"), by = 900, length.out = 10)
time_seq_02 <- format(time_seq_01,usetz = TRUE)

time_seq_02_lt <- as.POSIXlt(time_seq_02)
time_seq_02_lt$isdst <- as.POSIXlt(time_seq_01)$isdst
time_seq_03 <- as.POSIXct(time_seq_02_lt)

As far as I can tell, R's support for string-to-datetime doesn't include DST flags specified within the strings.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!