According to documentation at http://guides.rubyonrails.org/i18n.html#adding-date-time-formats, the best way to ask for specific formats for a date is to define them in /config/
[several years later...]
If you want to DRY up your date formats and/or you have legacy code with to_s
all over the place and don't plan to internationalize your app, you can do this:
I18n.t('date.formats').each do |key, value|
Date::DATE_FORMATS[key] = value
end
Then just define your formats in config/locales/en.yml
. Of course if you ever plan to translate your app, you'll need to change all occurrences of to_s
to use the I18n.l
method suggested below.
You can also use this without Rails. Just add the following before the above code:
require 'active_support/time'
I18n.load_path << 'en.yml'