在指定时区导入日期时间,而不考虑夏令时

编程入门 行业动态 更新时间:2024-10-10 11:28:45
本文介绍了在指定时区导入日期时间,而不考虑夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个从数据记录器获取的时间序列数据,该数据记录器设置为一个没有夏令时的时区( 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.

更多推荐

在指定时区导入日期时间,而不考虑夏令时

本文发布于:2023-11-23 20:13:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622749.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:夏令时   而不   时区   日期   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!