2014-10-17 49 views
0

我将当地时间(欧洲/巴黎)的2013时间表转换为UTC到UTC。 我使用下面的代码UTC转换的本地时区:DST更改发生在错误的时间

oasi <- read.csv("oasi.csv", sep=";", skip=28, header=FALSE) 
oasi$datetime <- as.POSIXct(oasi[,1], tz="Europe/Paris", format="%d.%m.%Y %H:%M:%S") 
oasi$utc <- oasi$datetime 
attr(oasi$utc, "tzone") <- "UTC" 

当我在打印的27/10/2013 DST更改02:00我看到下面的奇怪行为

    datetime     utc 
43063 2013-10-27 02:05:00 2013-10-27 00:05:00 
43064 2013-10-27 02:15:00 2013-10-27 00:15:00 
43065 2013-10-27 02:25:00 2013-10-27 00:25:00 
43066 2013-10-27 02:35:00 2013-10-27 00:35:00 
43067 2013-10-27 02:45:00 2013-10-27 01:45:00 
43068 2013-10-27 02:55:00 2013-10-27 01:55:00 
43069 2013-10-27 02:05:00 2013-10-27 00:05:00 
43070 2013-10-27 02:15:00 2013-10-27 00:15:00 
43071 2013-10-27 02:25:00 2013-10-27 00:25:00 
43072 2013-10-27 02:35:00 2013-10-27 00:35:00 
43073 2013-10-27 02:45:00 2013-10-27 01:45:00 
43074 2013-10-27 02:55:00 2013-10-27 01:55:00 
43075 2013-10-27 03:05:00 2013-10-27 02:05:00 
43076 2013-10-27 03:15:00 2013-10-27 02:15:00 
43077 2013-10-27 03:25:00 2013-10-27 02:25:00 
43078 2013-10-27 03:35:00 2013-10-27 02:35:00 
43079 2013-10-27 03:45:00 2013-10-27 02:45:00 
43080 2013-10-27 03:55:00 2013-10-27 02:55:00 

看来DST应用在02:35和02:45之间,而不是在03:00。 这很奇怪,我不明白它为什么会发生。本地日期时间的

dput输出02:35和02:45:

structure(c(1382834100, 1382838300), class = c("POSIXct", "POSIXt"), tzone = "Europe/Paris") 

可能是一个OS错误?我正在使用Win7 64位。

+0

请将'dput(oasi $ datetime [<相关时间>])的输出添加到您的问题中。 – Roland 2014-10-17 09:37:40

+0

补充,希望有帮助 – 2014-10-17 09:44:30

回答

2

我可以重现这样的:

as.POSIXct(c("27.10.2013 02:35:00", "27.10.2013 02:45:00"), tz="Europe/Paris", format="%d.%m.%Y %H:%M:%S") 
#[1] "2013-10-27 02:35:00 CEST" "2013-10-27 02:45:00 CET" 

你应该知道,你的输入是模糊的。时钟在一个小时后切换,所以这个小时存在两次。我不知道在这种情况下如何选择时区。这似乎有点武断。

您需要的时区信息添加到您的输入:

as.POSIXct(c("27.10.2013 02:35:00 +0100", "27.10.2013 02:45:00 +0100"), tz="Europe/Paris", format="%d.%m.%Y %H:%M:%S %z") 
#[1] "2013-10-27 02:35:00 CET" "2013-10-27 02:45:00 CET" 
as.POSIXct(c("27.10.2013 02:35:00 +0200", "27.10.2013 02:45:00 +0200"), tz="Europe/Paris", format="%d.%m.%Y %H:%M:%S %z") 
#[1] "2013-10-27 02:35:00 CEST" "2013-10-27 02:45:00 CEST" 
+0

谢谢你的回答,你是对的,它是任意选择的。所以我需要手动添加时区字符串以消除这种歧义。您是否知道可用于此任务的特定功能,或者从头开始检测两个观察之间的间隔变化是否更容易? – 2014-10-17 11:43:20

+0

好吧,我怀疑你的数据可能实际上都是CET(或GMT)。录制数据时容易出现歧义,这很愚蠢。 – Roland 2014-10-17 11:46:14

+0

是的,它是一个10分钟间隔的CET数据集,我试图了解如何以最一致和最有效的方式以UTC格式转换此数据集。 – 2014-10-17 11:48:36

0

至于建议由@roland我试图找到的DST更改,添加时区信息,并消除了从最初的CET数据集的模糊性。此代码对于一年数据集似乎工作正常。

oasi <- read.csv("oasi.csv", sep=";", skip=28, header=FALSE, stringsAsFactors=FALSE) 
dst.index <- which(abs(difftime(as.POSIXct(oasi[,1], tz="UTC", format="%d.%m.%Y %H:%M:%S"), 
         as.POSIXct(c(oasi[1,1], head(oasi[,1],-1)), tz="UTC", format="%d.%m.%Y %H:%M:%S"), 
         units = "mins")) > 10) 

oasi[1:dst.index[1],1] <- paste(oasi[1:dst.index[1],1], "+0100") 
oasi[dst.index[1]:dst.index[2],1] <- paste(oasi[dst.index[1]:dst.index[2],1], "+0200") 
oasi[-1:-dst.index[2],1] <- paste(oasi[-1:-dst.index[2],1], "+0100") 

oasi$datetime <- as.POSIXct(oasi[,1], tz="Europe/Paris", usetz=true, format="%d.%m.%Y %H:%M:%S %z") 
相关问题