Rails: How to make Date strftime aware of the default locale? Rails: How to make Date strftime aware of the default locale? ruby ruby

Rails: How to make Date strftime aware of the default locale?


Use the l (alias for localize) method instead of raw strftime, like this:

l(date, format: '%B %d, in the year %Y')

See here for more information, hope that helps.

You can also define 'named' formats, a couple of them (short, long) are already predefined.


you can also make it shorter:

l(some_date, :format => '%d %B %Y')


In es.yml put:

es:  date:    formats:      default: "%d / %m / %Y"

In index.html.erb put:

<%= l somemodel.datefield %>