我开始尝试使用R中的lubridate包。我注意到now(tzone="EST")
计算结果如下:
[1] "2015-08-25 13:01:08 EST"
当使用now(tzone="PST")
时,会出现警告:
[1] "2015-08-25 18:02:16 GMT"
Warning message:
In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'PST'
那么什么是已知的时区? Lubridate中的有效时区有一个答案。但我想看看自己如何回答这个问题(通过查找包本身)。我查看了now()
函数:
> now
function (tzone = "")
with_tz(Sys.time(), tzone)
<environment: namespace:lubridate>
那么,我看了一下with_tz
函数:
> with_tz
function (time, tzone = "")
{
check_tz(tzone)
if (is.POSIXlt(time))
new <- as.POSIXct(time)
else new <- time
attr(new, "tzone") <- tzone
reclass_date(new, time)
}
<environment: namespace:lubridate>
>
那么我就检查一下check_tz
函数:
> check_tz
Error: object 'check_tz' not found
没有找到。我在本地的lubridate
R库文件中查找check_tz
,但是没有找到任何东西。我进行了谷歌搜索,并找到了这个GitHub页面。它就在那里!看起来olson_time_zones()
列出了已知的时区。(更新:olson_time_zones()
只返回一部分可用的时区。有关更多详细信息,请参见下面我的评论。)特别地,
> now(tzone="America/Los_Angeles")
[1] "2015-08-25 11:11:14 PDT"
问:如果GitHub上没有一个好的文件或StackOverflow上没有答案,我该如何回答关于已知时区列表的问题?换句话说,我能通过挖掘本地的lubridate
库文件来找到答案吗?
问:是否有一个更通用的原则来挖掘R包值得指出?
stringr :: str_subset(olson_time_zones(),“EST”)
什么也没有返回。看起来lubridate
也使用OlsonNames()
作为tzone
。str_subset(OlsonNames(),“EST”)
返回“EST”和“EST5EDT”。str_subset(OlsonNames(),“PDT”)
返回“PST8PDT”。 - lowndrulolson_time_zones
- 'here
和olson_time_zones
已被弃用,推荐使用new
和基本的OlsonNames
。' - thelatemail