Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 0.96 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Customizing datetime format in en.yml in Rails 3
  2. "en-US":
  3.   date:
  4.     formats:
  5.       default: "%Y-%m-%d"
  6.       **short: "short %b %d"**
  7.        
  8. time:
  9.     formats:
  10.       default: "%a, %d %b %Y %H:%M:%S %z "
  11.       **short: "short %B %d, %Y"**
  12.        
  13. <%= l item.create_date, :format => :short %>
  14.        
  15. datetime:
  16.     formats:
  17.       short: "short %B %d, %Y"
  18.        
  19. en:
  20.   time:
  21.     formats:
  22.       short_datetime: %B %d, %Y
  23.       long_datetime:  %B %d, %Y, at %r
  24.       hammer_datetime: STOP! %B %d, %Y, is HAMMERTIME!
  25.       # and so on... da dum... da dum...
  26.        
  27. <%= l item.create_date, :format => :short_datetime %>
  28.        
  29. en:
  30.   datetime:
  31.     formats:
  32.       default: %B %d, %Y
  33.        
  34. # In your Application Helper
  35. def localize_datetime(dt)
  36.   # quick-and-dirty demo... doesn't accept different format options and stuff...
  37.   dt.strftime(I18n.t(:"datetime.formats.default", {:locale => I18n.locale }))
  38. end
  39. def ld(dt)
  40.   localize_datetime(dt)
  41. end
  42. # or something like that...
  43.        
  44. <%= ld item.create_date %>