Question

Where can I find a list of all legal time names for R function as.POSIXct?

as.POSIXct("1970-01-01",tz="CST") generates a warning that "CST" (Central Standard Time) is unknown.

Was it helpful?

Solution

?Sys.timezone has some hints, specifically to look in: "R_HOME/share/zoneinfo/zone.tab" (R_HOME is the directory R is installed in). Keep in mind that time zones are nasty and many of their nuances are operating system (and locale?) specific.

In your specific case, you want "CST6CDT" instead of "CST".

OTHER TIPS

Timezone stuff can drive you NUTS!!

Being located in Germany, this is what I used to do to set my tz:

> options(tz="Europe/Berlin")

Doing so, I always wondered why R would throw "unknown timezone" warnings:

> t <- "2011-11-08 09:42:00"
> as.POSIXct(t, tz=getOption("tz"))
[1] "2011-11-08 09:42:00 CET"
Warning messages:
1: In strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'MET-1MST'
2: In as.POSIXct.POSIXlt(x) : unknown timezone 'MET-1MST'
3: In strptime(x, f, tz = tz) : unknown timezone 'MET-1MST'
4: In as.POSIXct.POSIXlt(as.POSIXlt(x, tz, ...), tz, ...) :
  unknown timezone 'MET-1MST'
5: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'MET-1MST'

Someday I found out that setting tz via options() was not enough as the environment variable TZ is not affected and hence all the the trouble:

> Sys.getenv("TZ")
[1] "MET-1MST"

Changing this should do away with the nasty warnings:

> Sys.setenv(TZ="Europe/Berlin")
> Sys.getenv("TZ")
[1] "Europe/Berlin"
> as.POSIXct(t, tz=getOption("tz"))
[1] "2011-11-08 09:42:00 CET"

Most R platforms use the time-zone database compiled by David Olson, where the preferred reference is by location. There names are a bit outdated but they will help you get going.

Find a full list of available time zones (doesn't work on windows):

OlsonNames()

For folks running windows that OlsonNames() doesn't work: See the full list here.

Or read up in more detail here http://www.twinsun.com/tz/tz-link.htm

Couldn't find it in that location on my make but found a zipped version in a source directory. Here's a list of timezone abbreviations that appear at the top level of the zones.tab file:

CET, CST6CDT, Cuba, EET, EST, EST5EDT, Egypt, Eire, Factory, GB, GB-Eire, GMT,
GMT+0, GMT-0, GMT0, Greenwich, HST, Hongkong, Iceland, Iran, Israel, Jamaica, Japan,
Kwajalein, Libya, MET, MST, MST7MDT, NZ, NZ-CHAT, Navajo, PRC, PST8PDT, Poland, Portugal,
ROC, ROK, Singapore, Turkey, UCT, UTC, Universal, W-SU, WET, Zulu

There are also folders with continent/country names, which have more options such as the America/New_York example above.:

Africa/     Asia/       Canada/     Indian/
America/    Atlantic/   Chile/      Mexico/
Antarctica/ Australia/  Etc/        Pacific/
Arctic/     Brazil/     Europe/     US/

This was found in the /R-2.11.1/src/extra/tzone/zoneinfo.zip file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top