Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
949 views
in Technique[技术] by (71.8m points)

unknown timezone name in R strptime/as.POSIXct

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...