在Windows机器上使用R
as.POSIXct('2018-11-04 01:30:00', tz = 'America/Chicago')
# "2018-11-04 01:30:00 CDT"
as.POSIXct('2018-11-04 01:40:00', tz = 'America/Chicago')
# "2018-11-04 01:40:00 CST"
我知道这些时间是模糊的(技术上可以是CDT或CST(,R可能很难解释。然而,这些结果的随机性使得在这些时间段内转换时间变得困难。是否有一种方法可以实现更一致的结果?
如果您查看整数表示,您会注意到:
# divide by 60 to convert to minutes from seconds
as.integer(as.POSIXct('2018-11-04 01:30:00', tz = 'America/Chicago'))/60
# [1] 25688550
as.integer(as.POSIXct('2018-11-04 01:40:00', tz = 'America/Chicago'))/60
# [1] 25688620
这两个时间间隔70分钟,这意味着如果CDT继续,后者对应于2:40;这对我来说似乎很一致。在快速搜索America/Chicago
时区夏令时开关的具体细节时,我找不到任何参考资料。
此外,您可能会考虑在这种情况下查看POSIXlt
表示:
dput(as.POSIXlt('2018-11-04 01:30:00', tz = 'America/Chicago'))
# structure(list(sec = 0, min = 30L, hour = 1L, mday = 4L, mon = 10L,
# year = 118L, wday = 0L, yday = 307L, isdst = 1L, zone = "CDT",
# gmtoff = NA_integer_), class = c("POSIXlt", "POSIXt"), tzone = "America/Chicago")
dput(as.POSIXlt('2018-11-04 01:40:00', tz = 'America/Chicago'))
# structure(list(sec = 0, min = 40L, hour = 1L, mday = 4L, mon = 10L,
# year = 118L, wday = 0L, yday = 307L, isdst = 0L, zone = "CST",
# gmtoff = NA_integer_), class = c("POSIXlt", "POSIXt"), tzone = "America/Chicago")
请注意两个对象之间isdst
的差异。。。
为了继续,我们真的需要找到一个关于CDT/CST如何划分的权威来源。但是FWIW,切换的确切时间似乎是1:30:05
:
as.POSIXct('2018-11-04 01:30:05', tz = 'America/Chicago')
# [1] "2018-11-04 01:30:05 CDT"
as.POSIXct('2018-11-04 01:30:06', tz = 'America/Chicago')
# [1] "2018-11-04 01:30:06 CST"
(为了弄清楚这一点,我查看了的输出:(
with(expand.grid(second = 0:59, minute = 30:40),
as.POSIXct(sprintf('2018-11-04 01:%02d:%02d', minute, second),
tz = 'America/Chicago'))