2014-04-14 40 views

回答

4

您可以定義一個新的格式:

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

+0

你解決方案對我來說很完美。 – user1066183

相關問題