Reputation: 38359
I'm not that familiar with I18N in Rails so bear with me. Trying to set a custom date & time format:
#config/locales/en.yml
en:
date:
formats:
long_dateweek: "%A, %B %d, %Y"
time:
formats:
very_short: "%H:%M"
But when I try to use them I just get the default formats:
1.9.3p194 :001 > Time.now.to_date.to_s(:long_dateweek)
=> "2012-08-22"
1.9.3p194 :002 > Time.now.to_time.to_s(:very_short)
=> "2012-08-22 16:12:47 -0700"
Tried restarting console (and even the server) to no avail... What'd I miss?
Upvotes: 4
Views: 2090
Reputation: 244
@alexsanford1 has the right answer. I modified mine below to work in the view.
<%= l Time.now, :format => :very_short %>
Upvotes: 3
Reputation: 3727
You need to use the I18n.l
method as follows:
1.9.3p194 :001 > I18n.l Time.now.to_date, :format => :long_dateweek
=> "Wednesday, August 22, 2012"
1.9.3p194 :002 > I18n.l Time.now, :format => :very_short
=> "23:03"
You can also use the l
helper method in your views. Look at this rails guide for more information.
Upvotes: 3