Custom Rails 3 Date Format
- by Jack
Hi,
I am trying to format a date as follows using Rails 3; 3rd June 2003.
This is not a standard way of showing the date, so I have looked into a custom way of doing it. Rails 3.0 documentation here suggests that I add a file at config/initializers/time_formats.rb containing the following code:
Time::DATE_FORMATS[:custom_date] = lambda { |time| time.strftime("#{time.day.ordinalize} %B %Y") }
And then call it using something like:
<%= document.publish_date.to_formatted_s(:custom_date) %>
However this isn't working and the date is being formatted as YYYY-MM-YY. Does anyone have any suggestions?
Cheers