R 转换外语日期时间格式不起作用
我正在尝试使用包 parsedate
将几种不同的日期时间格式解析/转换为统一/同质格式,问题是有些日期将采用英语(我的机器语言),有些将采用西班牙语让我来说明一下:
我有两个向量:
#English dates
dates<-c("2016 jun 15 8:39 p.m","2016 apr 2 8:39 a.m","2016 dec 2 8:39 a.m")
#Spanish dates
fechas<-c("2016 junio 15 8:39 p.m","2016 abril 2 8:39 a.m","2016 diciembre 2 8:39 a.m")
我注意到函数 parse_date()
正确地将向量 dates
转换为所需的输出格式,但是当尝试解析向量时对于西班牙日期,即使在将本地时间更改为“西班牙语”,如下所示:
#Parsing english dates
parsedate::parse_date(dates)
> parsedate::parse_date(dates)
[1] "2016-06-15 08:39:00 UTC" "2016-04-02 08:39:00 UTC" "2016-12-02 08:39:00 UTC"
#Parsing spanish dates
Sys.setlocale("LC_TIME", "Spanish")
parsedate::parse_date(fechas)
> Sys.setlocale("LC_TIME", "Spanish")
[1] "Spanish_Spain.1252"
> parsedate::parse_date(fechas)
[1] "2016-01-15 08:39:00 UTC" "2016-01-02 08:39:00 UTC" "2016-01-02 08:39:00 UTC"
西班牙语输出是错误的,因为它应该在英语日期中返回相同的输出,我尝试了多种方法将机器的本地时间正确更改为西班牙语,但没有成功。< br> 如果您能帮助我,我将非常感激。
I am trying to use the package parsedate
to parse/convert several different datetime formats into a uniform/homogenous format the issue is that some dates will be in English (my machine language) and some will be in Spanish allow me to illustrate:
I have two vectors:
#English dates
dates<-c("2016 jun 15 8:39 p.m","2016 apr 2 8:39 a.m","2016 dec 2 8:39 a.m")
#Spanish dates
fechas<-c("2016 junio 15 8:39 p.m","2016 abril 2 8:39 a.m","2016 diciembre 2 8:39 a.m")
I noticed that the function parse_date()
correctly converts the vector dates
into the desired output format, but when trying to parse the vector with Spanish dates it does not work even when changing local time to "Spanish" as is shown below:
#Parsing english dates
parsedate::parse_date(dates)
> parsedate::parse_date(dates)
[1] "2016-06-15 08:39:00 UTC" "2016-04-02 08:39:00 UTC" "2016-12-02 08:39:00 UTC"
#Parsing spanish dates
Sys.setlocale("LC_TIME", "Spanish")
parsedate::parse_date(fechas)
> Sys.setlocale("LC_TIME", "Spanish")
[1] "Spanish_Spain.1252"
> parsedate::parse_date(fechas)
[1] "2016-01-15 08:39:00 UTC" "2016-01-02 08:39:00 UTC" "2016-01-02 08:39:00 UTC"
The Spanish output is wrong because it should return the same output in the English dates, I have tried several ways to properly change the local time of my machine to Spanish with no luck.
I will be very thankful if you can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此处https://github.com/tidyverse/lubridate/issues/781
See here https://github.com/tidyverse/lubridate/issues/781