timezones in R: how to avoid ambiguous terms such as EST?

大城市里の小女人 提交于 2019-12-06 00:43:45

问题


I have a series of character timestamps in R. When I change their class to POSIXct using intuitive methods, R assigns the ambiguous timezone EST.

For example:

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 = "") 

all produce the same output on my two (Mac and Windows) boxes:

"2012-08-06 15:32:00 EST"

The problem here is EST could be any number of timezones: Eastern Standard Time in the USA, or Australian Eastern Standard Time, or another timezone in Canada (from ?timezone):

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.

There is a method to set the timezone which avoids this EST label. It is alluded to, but not fully explained in the R ?timezone help. Setting x as the time of the Curiosity landing on Mars as reported by an Australian news service:

x <- as.POSIXct("2012-08-06 15:32:00", tz = "Etc/GMT-10")
x
"2012-08-06 15:32:00 GMT-10"

And we can test that this is correct by converting it to a US timezone and checking with a Californian news report:

y <- format(x, tz = "America/Los_Angeles")
y
"2012-08-05 22:32:00"

If using this Etc/GMT+n or Etc/GMT-n notation, please beware of the following caveat from ?timezone :

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:


The 1st and 3rd lines in your first example produce the same output because tz="" is the default for as.POSIXct. The second line is more interesting because the timezone is explicitly defined.

But note that "EST" is only how the timezone is printed by default. The tzone attribute is still unambiguous.

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"


来源:https://stackoverflow.com/questions/11927433/timezones-in-r-how-to-avoid-ambiguous-terms-such-as-est

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!