format a date in to the format october 13, 2014 in ruby

You can format a date in Ruby using the strftime method.

Here's an example of how to format October 13, 2014, into the format "October 13, 2014":

main.rb
date = DateTime.new(2014,10,13)
formatted_date = date.strftime("%B %d, %Y")
puts formatted_date # "October 13, 2014"
117 chars
4 lines

In the strftime method, %B represents the full month name, %d represents the day of the month with a zero-padded two-digit number, and %Y represents the year with century.

related categories

gistlibby LogSnag