R strptime/as.POSIXct 中的未知时区名称
在哪里可以找到 R 函数 as.POSIXct
的所有合法时间名称的列表?
as.POSIXct("1970-01-01",tz="CST")
生成一条警告,提示“CST”(中部标准时间)未知。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
时区的东西会让你发疯!!
由于位于德国,这就是我用来设置 tz 的方法:
这样做时,我总是想知道为什么 R 会抛出“未知时区”警告:
有一天我发现通过
options()
还不够,因为环境变量TZ
不受影响,因此会出现所有麻烦:更改此设置应该消除令人讨厌的警告:
Timezone stuff can drive you NUTS!!
Being located in Germany, this is what I used to do to set my tz:
Doing so, I always wondered why R would throw "unknown timezone" warnings:
Someday I found out that setting tz via
options()
was not enough as the environment variableTZ
is not affected and hence all the the trouble:Changing this should do away with the nasty warnings:
?Sys.timezone
有一些提示,特别是要查看:"R_HOME/share/zoneinfo/zone.tab"
(R_HOME
是目录R 安装在)。请记住,时区是令人讨厌的,并且它们的许多细微差别是特定于操作系统(和区域设置?)的。在您的具体情况下,您需要
"CST6CDT"
而不是"CST"
。?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"
.大多数 R 平台使用 David Olson 编译的时区数据库,其中首选参考是按位置。这些名称有点过时,但它们会帮助您继续前进。
查找可用时区的完整列表(不适用于 Windows):
对于运行 OlsonNames() 不起作用的 Windows 的用户:在此处查看完整列表。
或者在这里阅读更多详细信息 http://www.twinsun.com/tz/tz-链接.htm
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):
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
在我的 make 上的该位置找不到它,但在源目录中找到了压缩版本。以下是出现在
zones.tab
文件顶层的时区缩写列表:还有带有大陆/国家/地区名称的文件夹,其中包含更多选项,例如
America/New_York< /code> 上面的例子:
这是在
/R-2.11.1/src/extra/tzone/zoneinfo.zip
文件中找到的。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:There are also folders with continent/country names, which have more options such as the
America/New_York
example above.:This was found in the
/R-2.11.1/src/extra/tzone/zoneinfo.zip
file.TL;DR:使用此命令设置
tz
选项以使警告消失现在,在 R 会话中设置了时区,警告将会消失。使用
OlsonNames()
查看您可以使用的时区的完整列表(或向下滚动查看下面的完整列表)。相关信息
如果
options("tz")
返回NULL
表示当前R会话没有设置时区:查看当前设置的时区带有
options("tz")
的选项这是时区的完整列表。您可以使用
OlsonNames()
命令生成列表。TL;DR: Set the
tz
option with this command to make the warning go awayNow a timezone is set in your R session and the warning will disappear. Use
OlsonNames()
to see a full list of timezones you can use (or scroll down for full list below).Related info
If
options("tz")
returnsNULL
that means no timezone has been set for the current R session:View the currently set timezone option with
options("tz")
Here is a full list of timezones. You can generate the list with the
OlsonNames()
command.