Custom Rails 3 Date Format
Posted
by Jack
on Stack Overflow
See other posts from Stack Overflow
or by Jack
Published on 2010-06-13T11:18:30Z
Indexed on
2010/06/13
11:22 UTC
Read the original article
Hit count: 1841
ruby-on-rails
|date
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
© Stack Overflow or respective owner