Take the 2-minute tour ×

I have my default locale set in the environment.rb as de(German).

I also see all the error messages in German, so the locale is also picked up by the server. But when I try to print date with strftime like following ..

some_date.strftime('%B, %y') # this prints January, 11 instead of Januar, 11

How can I print the date according to the default locale ?

regards, Hardik

share|improve this question

3 Answers 3

up vote 29 down vote accepted

Use the localize or l method instead of raw strftime. See here. Hope that helps.

share|improve this answer
How to print the date in format with localize ? Does it accept any formatting string like '%B, %y' ? –  rangalo Jan 4 '11 at 9:58
I figured it out: I18n.localize(some_date, :format => '%B, %y' Thanks –  rangalo Jan 4 '11 at 10:17
You'll want to make sure you have this gem installed: github.com/svenfuchs/rails-i18n That way you can have different locale's and call their format: short or whatever you'd like to reference. Look here for examples on references: github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml –  bcackerman Mar 10 '13 at 17:31
Or you can do something like this once you have that gem I mentioned above installed... l @item.created_at, :format => "%b %e, %Y", :locale => 'en' –  bcackerman Mar 10 '13 at 17:36

you can also make it shorter:

l(some_date, :format => '%d %B %Y')
share|improve this answer

In es.yml put:

      default: "%d / %m / %Y"

In index.html.erb put:

<%= l somemodel.datefield %>
share|improve this answer

Your Answer


