在Rails我试图本地化日期:Rails的另一种格式转换当前日期
2.1.1 :005 > Date.today
=> Mon, 14 Apr 2014
2.1.1 :006 > I18n.localize(Date.today)
=> "14/04/2014"
2.1.1 :007 >
第二输出不是第一的正确翻译!
你能帮我吗?
在Rails我试图本地化日期:Rails的另一种格式转换当前日期
2.1.1 :005 > Date.today
=> Mon, 14 Apr 2014
2.1.1 :006 > I18n.localize(Date.today)
=> "14/04/2014"
2.1.1 :007 >
第二输出不是第一的正确翻译!
你能帮我吗?
您可以定义一个新的格式:
en:
date: # there is also a section for datetime and time
formats:
day_month_abbr: "%a, %d %b %Y"
,并使用它像这样:
I18n.localize(Date.today, format: :day_month_abbr)
# => "Mon, 14 Apr 2014"
或者您可以覆盖默认格式:
en:
date:
formats:
default: "%a, %d %b %Y"
然后你不需要给任何说法:
I18n.l(Date.today) #=> "Mon, 14 Apr 2014"
所有可用于日期时间/时间/日期这里的通配符列表:http://apidock.com/ruby/DateTime/strftime
第二次上传实际上是正确的翻译。
如果你想自定义输出格式,看看这里的文档: http://edgeguides.rubyonrails.org/i18n.html#adding-date-time-formats
你解决方案对我来说很完美。 – user1066183