Posted on 30th October 20092 Responses
Rails: Predefining date formats

To have a predefined set of formats (e.g. to make a short version looking like 11/2009 and a long version displaying 01.11.2009 or 2009/11/01) you can define them in config/.rb, right after the final end notation:


Time::DATE_FORMATS[:short] = "%d.%m.%Y at %H:%M"
Time::DATE_FORMATS[:news] = "%d.%m.%y"

Share this on:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • email
  • MisterWong
  • MySpace
  • Reddit
  • RSS
  • Yahoo! Bookmarks

Related posts

Comments
comment by t.morgan
Posted on 05.11.2009 at 18:45

Can you post a link to some more resources (or write them down in a post) – I’m trying to do extensive date formatting in a portal solution but I would like to have some more information than just api.rubyonrails.org.

comment by Stefan Schuchlenz
Posted on 05.11.2009 at 18:49

Of course, let me look, I guess I’ve got some links lying around somewhere ;) (I’ll post them here as a follow up comment)

Leave a Response
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img src="">