timezones in R: how to avoid ambiguous terms such as EST?
我在r中有一系列字符时间戳。当我使用直观的方法将它们的类更改为
例如:
1 2 3 | as.POSIXct("2012-08-06 15:32:00") as.POSIXct("2012-08-06 15:32:00", tz ="Australia/Brisbane") as.POSIXct("2012-08-06 15:32:00", tz ="") |
所有这些都在我的两个(Mac和Windows)框上产生相同的输出:
1 | "2012-08-06 15:32:00 EST" |
这里的问题是
Beware that some of these designations may not be what you think: in
particular EST is a time zone used in Canada without daylight savings
time, and not EST5EDT nor (Australian) Eastern Standard Time.
有一种方法可以设置时区,从而避免使用此
1 2 3 | x <- as.POSIXct("2012-08-06 15:32:00", tz ="Etc/GMT-10") x "2012-08-06 15:32:00 GMT-10" |
我们可以通过将其转换为美国时区并查看加州新闻报告来测试这是否正确:
1 2 3 | y <- format(x, tz ="America/Los_Angeles") y "2012-08-05 22:32:00" |
如果使用此
Many systems support timezones of the form GMT+n and GMT-n, which are
at a fixed offset from UTC (hence no DST). Contrary to some usage (but
consistent with names such as PST8PDT), negative offsets are times
ahead of (east of) UTC, positive offsets are times behind (west of)
UTC.
第一个示例中的第一行和第三行产生相同的输出,因为
但请注意,默认情况下,
1 2 3 4 5 | R> x <- as.POSIXct("2012-08-06 15:32:00", tz="Australia/Brisbane") R> x [1]"2012-08-06 15:32:00 EST" R> attr(x,"tzone") [1]"Australia/Brisbane" |