Ruby DateTime format: How can I get 1, 2, 3, 4?

First of all, it seems that DateTime format variables are not documented anywhere, so +1 for anyone who can show this to me in rubydocs . Secondly, when looking at the code of the Date.strftime function Date.strftime I do not see anything that could allow me to do something like:

Thursday, September 9th 2010

Does anyone know if this is possible?

+6
ruby ruby-on-rails datetime-format
source share
2 answers

You may want to look here .

Summarizing

 time = DateTime.now time.strftime("%A, %B #{time.day.ordinalize} %Y") 

Note that you are using regular Ruby (2.0), which you need to call:

 require 'active_support/core_ext/integer/inflections' 
+24
source share

You can find all the% xx tools in the time documentation

http://ruby-doc.org/core/classes/Time.html#M000298

So you just need to do

 date.strftime('%A, %B %d %Y') 
-one
source share

All Articles