用葡萄牙语解析日期

时间:2018-03-12 23:28:45

标签: r lubridate

我有一些葡萄牙语的日期,我想解析。

dts = c('19-mai-17', '26-mai-17', '2-jun-17',  '9-jun-17',  '16-jun-17')
lubridate::parse_date_time(dts, orders = "d-b-y", locale = "pt-BR")

但它只返回与英语重叠的日期,同时抛出一些警告:

[1] NA               NA               "2017-06-02 UTC" "2017-06-09 UTC" "2017-06-16 UTC"
Warning messages:
1: In Sys.setlocale("LC_TIME", locale) :
  OS reports request to set locale to "pt-BR" cannot be honored
2: In Sys.setlocale("LC_TIME", locale) :
  OS reports request to set locale to "pt-BR" cannot be honored
3: In Sys.setlocale("LC_TIME", locale) :
  OS reports request to set locale to "pt-BR" cannot be honored
4:  2 failed to parse. 

我从https://web.archive.org/web/20161105200145/https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx

获得了locale代码

运行Windows 7

1 个答案:

答案 0 :(得分:1)

这可能只是使用正确的区域设置代码的问题。在MacOS上pt_BR对我来说很好。事实证明,在Windows上,您可能想尝试Portuguese_Brazil.1252。在任何情况下,使用

更改每个会话的LC_TIME区域设置
Sys.setlocale(category = "LC_TIME", locale = "pt_BR")