我有一个日期,当它用作英语时效果很好
> Date.strptime("Aug 02, 2015", "%b %d, %Y")
Sun, 02 Aug 2015
但是,当我使用另一种语言es
时,它不起作用。例如
> Date.strptime("ago 02, 2015", "%b %d, %Y")
ArgumentError: invalid date
文本字符串ago 02, 2015
本身来自另一个服务,我需要将其标准化为特定格式,例如
> I18n.localize(Date.strptime("Aug 02, 2015", "%b %d, %Y"), format: "%m/%d/%Y")
"08/02/2015"
有没有办法在 Ruby 中做到这一点,所以
> I18n.localize(Date.strptime("ago 02, 2015", "%b %d, %Y"), format: "%m/%d/%Y")
"08/02/2015"