2014-02-18 98 views
2

是否有一個快速的方法能夠ordinalize下面的代碼?Ordinalize嵌入式紅寶石

<%= time_tag(Date.today, :format=>'%A %d %b') %> 

的電流輸出讀取

Tuesday 18 Feb 

我想ordinalize日期顯示

Tuesday 18th Feb 

有什麼建議?

回答

3

寫入如下使用#ordinalize

<%= time_tag(Date.today, :format=>"%A #{Date.today.day.ordinalize} %b") %> 
+1

感謝那些很好的工作:) – MikeHolford

5

您可以使用Date::DATE_FORMATS添加新的自定義格式,並Integer.ordinalize拿到第幾天:

Date::DATE_FORMATS[:month_ordinal] = lambda { |date| 
    date.strftime("%A #{date.day.ordinalize}, %B") 
} 

>> Date.today.to_formatted_s(:month_ordinal) 
=> "Tuesday 18th, Feb"