
Untitled
By: a guest on
Jun 26th, 2012 | syntax:
None | size: 0.96 KB | hits: 13 | expires: Never
Customizing datetime format in en.yml in Rails 3
"en-US":
date:
formats:
default: "%Y-%m-%d"
**short: "short %b %d"**
time:
formats:
default: "%a, %d %b %Y %H:%M:%S %z "
**short: "short %B %d, %Y"**
<%= l item.create_date, :format => :short %>
datetime:
formats:
short: "short %B %d, %Y"
en:
time:
formats:
short_datetime: %B %d, %Y
long_datetime: %B %d, %Y, at %r
hammer_datetime: STOP! %B %d, %Y, is HAMMERTIME!
# and so on... da dum... da dum...
<%= l item.create_date, :format => :short_datetime %>
en:
datetime:
formats:
default: %B %d, %Y
# In your Application Helper
def localize_datetime(dt)
# quick-and-dirty demo... doesn't accept different format options and stuff...
dt.strftime(I18n.t(:"datetime.formats.default", {:locale => I18n.locale }))
end
def ld(dt)
localize_datetime(dt)
end
# or something like that...
<%= ld item.create_date %>