转换为格式不适用于 %B

问题描述 投票:0回答:1

以下两行代码都返回NA。

as.POSIXct("1-March-2021 11:45", format="%d-%B-%Y %H:%M")
as.POSIXct("1-Mar-2021 11:45", format="%d-%b-%Y %H:%M")

但是,如果我将

March
更改为
3
,它就可以正常工作。

as.POSIXct("1-3-2021 11:45", format="%d-%m-%Y %H:%M")

我被困在这里了。感谢您的任何提示。

r posixct
1个回答
1
投票

你的操作系统是什么?这在这里(在 Ubuntu 上)有效

> as.POSIXct("1-March-2021 11:45", format="%d-%B-%Y %H:%M")
[1] "2021-03-01 11:45:00 CST"
> as.POSIXct("1-Mar-2021 11:45", format="%d-%b-%Y %H:%M")
[1] "2021-03-01 11:45:00 CST"
> 

本地化也很重要。我在美英合一:

> Sys.getenv("LANG")
[1] "en_US.UTF-8"
> 
© www.soinside.com 2019 - 2024. All rights reserved.