SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict DevilBear's Avatar
    Join Date
    Oct 2001
    Location
    Hades
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Formatting dates in Ruby

    I'm reading http://www.ruby-doc.org/core/classes/Date.html and trying to figure out how to get what I want out of a Date object.

    I want to be able to take the date, give it a format string, and have it return a string with the date formatted properly.

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I think you want the Time object, specifically its strftime() method.

  3. #3
    SitePoint Addict DevilBear's Avatar
    Join Date
    Oct 2001
    Location
    Hades
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the database column is type date, and so I believe Rails turns that into a Date object automatically.

    I see a list of constants, like MONTHNAMES, at the link above... how do I access those? The Agile book shows a way to format dates using arrays like that, but I'd rather not re-create the arrays in my own code if they're already in the Date class.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •