可以采用“May 17, 2017”、“17/5/2017”等格式或“17-5-17 05:24:39”可以在 as.POSIXlt 中使用吗?
我刚刚读到 POSIXlt 和 POSIXct 之间的区别,据说 POSIXlt 是混合文本和字符格式,如“May, 6 1985”、“1990- 9-1”或“1/20/2012”。当我尝试此类操作时,我收到错误
as.POSIXlt("May, 6 1985")
# character string is not in a standard unambiguous format
(如何)我们可以将上面引用的格式的日期提交给 POSIXlt
?以下消息来源表示这种格式有效(如果我理解正确的话):1, 2。
I've just read about the difference between POSIXlt
and POSIXct
and it is said that POSIXlt is a mixed text and character format like "May, 6 1985", "1990-9-1" or "1/20/2012". When I try such kind of things I get an error
as.POSIXlt("May, 6 1985")
# character string is not in a standard unambiguous format
(How) can we dates with format as quoted above put forward to POSIXlt
? Here are sources saying that such format works (if I get them right): 1, 2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读
?strptime
了解指定时间格式的所有详细信息。在本例中,您需要%b
(月份名称)、%d
(月份中的某天)、%Y
(4 位数字年份) 。 (这仅适用于英语区域设置,因为月份名称是特定于区域设置的。)Read
?strptime
for all the details of specifying a time format. In this case you want%b
(for month name),%d
(day of month),%Y
(4-digit year). (This will only work with an English locale setting as the month names are locale-specific.)如果您有甲酸盐的混合输入,您可以使用
lubridate
包中的parse_date_time
。注意
c("ymd", "mdy", "dmy")
,因为这决定了第一个找到的第一个转换的顺序。考虑到6-1-2000
会遇到mdy
在dmy
之前有效,因此这意味着它将是六月一日而不是一月六日。If you have mixed input of formates you can use
parse_date_time
from thelubridate
package.note on
c("ymd", "mdy", "dmy")
as this determines the order on first found first converted. Consider6-1-2000
will encountermdy
as valid beforedmy
so this means it will be first of June and not sixth of January.