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

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

问题描述

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

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).

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

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"

以下是春季 DST 更改的三个时间戳,每个时间戳相隔 1 小时:

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"

如您所见,时钟从 1:59 跳到 3:00,因此 2:00 无效,因此不适用.此外,我可以使用 tz="UTC" 让它忽略 DST 更改.但是,我宁愿保留正确的时区,因为我有其他数据系列记录 with DST(NZDT 或 UTC+13:00)我想融入(通过 merge)供我分析.

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.

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

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?

推荐答案

可以使用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)

其中有几个 .tab 文件不是时区但包含一些信息,但我的 regex-fu 不够好,无法使用 dir<的模式参数排除它们/代码>.

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天全站免登陆