• 2

I want to display dates in the format: short day of week, short month, day of month without leading zero but including "th", "st", "nd", or "rd" suffix.

For example, the day this question was asked would display "Thu Oct 2nd".

I'm using Ruby 1.8.7, and Time.strftime just doesn't seem to do this. I'd prefer a standard library if one exists.

Use the ordinalize method from 'active_support'.

>> time =
=> Fri Oct 03 01:24:48 +0100 2008
>> time.strftime("%a %b #{}")
=> "Fri Oct 3rd"

Note, if you are using IRB with Ruby 2.0, you must first run:

require 'active_support/core_ext/integer/inflections'
  • 0
Reply Report