在指定时区导入日期时间,而不考虑夏令时 [英] Import date-time at a specified timezone, disregard Daylight Savings Time

查看:129
本文介绍了在指定时区导入日期时间,而不考虑夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从数据记录器获取的时间序列数据,该数据记录器设置为一个没有夏令时的时区( NZST 或UTC + 12:00),则数据跨度为数年。数据记录器不考虑DST更改,而是在有/没有DST的情况下与本地时间同步(取决于部署它的人)。



但是,当我将数据输入R ,我无法正确使用 as.POSIXct 忽略DST。我在具有以下设置的Windows计算机上使用的是R 2.14.0:

 > Sys.timezone()
[1] NZDT
> Sys.getlocale( LC_TIME)
[1] English_New Zealand.1252

这是整个春季DST更改的三个时间戳,每个时间戳间隔1小时:

  ts_str<-c( 28/09/2008 01:00, 28/09/2008 02:00, 28/09/2008 03:00)
> as.POSIXct(ts_str,format =%d /%m /%Y%H:%M,tz =)
[1] 2008-09-28 01:00:00 NZST NA
[3] 2008-09-28 03:00:00 NZDT
> as.POSIXct(ts_str,format =%d /%m /%Y%H:%M,tz = UTC)
[1] 2008-09-28 01:00:00 UTC 2008-09-28 02:00:00 UTC
[3] 2008-09-28 03:00:00 UTC

如您所见,时钟从1:59跳到3:00,所以2:00无效,因此不适用。此外,我可以使用 tz = UTC 使其忽略DST更改。但是,我宁愿保留正确的时区,因为我想将其他数据序列与 DST(NZDT或UTC + 13:00)一起记录下来(通过合并)进行分析。



如何配置 tz 参数在MS Windows计算机上?我尝试了很多事情,例如 NZST,新西兰标准时间, UTC + 12:00, + 1200等,但是没有运气。还是修改其他设置?

解决方案

您可以使用 tz = Etc / GMT + 12

  as.POSIXct(ts_str,format =%d /%m /%Y %H:%M,tz = Etc / GMT + 12)
[1] 2008-09-28 01:00:00 GMT + 12 2008-09-28 02:00:00 GMT + 12
[3] 2008-09-28 03:00:00 GMT + 12

有关可用时区使用的完整列表,

  dir(file.path(R.home( share ), zoneinfo),recursive = TRUE)

有几个.tab文件在那里不是时区,但包含一些信息,但是我的正则表达式不足以使用 dir 的pattern参数将它们排除。 p>

I have time series data obtained from a data logger that was set to one time zone without daylight savings (NZST or UTC+12:00), and the data spans a few years. Data loggers don't consider DST changes, and are synchronized to local time with/without DST (depending who deployed it).

However, when I get the data into R, I'm unable to properly use as.POSIXct to ignore DST. I'm using R 2.14.0 on a Windows computer with these settings:

> Sys.timezone()
[1] "NZDT"
> Sys.getlocale("LC_TIME")
[1] "English_New Zealand.1252"

Here are three timestamps across the spring DST change, each are spaced 1 hour apart:

> ts_str <- c("28/09/2008 01:00", "28/09/2008 02:00", "28/09/2008 03:00")
> as.POSIXct(ts_str, format="%d/%m/%Y %H:%M", tz="")
[1] "2008-09-28 01:00:00 NZST" NA
[3] "2008-09-28 03:00:00 NZDT"
> as.POSIXct(ts_str, format="%d/%m/%Y %H:%M", tz="UTC")
[1] "2008-09-28 01:00:00 UTC" "2008-09-28 02:00:00 UTC"
[3] "2008-09-28 03:00:00 UTC"

As you can see, the clocks jumped forward at 1:59 to 3:00, so 2:00 is invalid, thus NA. Furthermore, I can use tz="UTC" to get it to ignore DST changes. However, I'd rather keep the correct time zone since I have other data series recorded with DST (NZDT or UTC+13:00) that I'd like to blend in (via merge) for my analysis.

How do I configure the tz parameter on a MS Windows computer? I've tried many things, such as "NZST", "New Zealand Standard Time", "UTC+12:00", "+1200", etc., but no luck. Or do I modify some other setting?

解决方案

You can use tz="Etc/GMT+12":

as.POSIXct(ts_str, format="%d/%m/%Y %H:%M", tz="Etc/GMT+12")
[1] "2008-09-28 01:00:00 GMT+12" "2008-09-28 02:00:00 GMT+12"
[3] "2008-09-28 03:00:00 GMT+12"

For a full list of available timezones use,

dir(file.path(R.home("share"),"zoneinfo"), recursive=TRUE)

There are a couple of of .tab files in there which aren't timezones but hold some information, but my regex-fu isn't good enough to be able to exclude them with the pattern argument to dir.

这篇关于在指定时区导入日期时间,而不考虑夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆