convert ruby date to string without losing format

ruby, ruby-on-rails-3

Solution

Use Date#strftime there are so many options

require 'date'


date = Date.parse("Sun, 15 Sep 2013") # => #<Date: 2013-09-15 ((2456551j,0s,0n),+0s,2299161j)>

date.strftime("%a, %d %b %Y") # => "Sun, 15 Sep 2013"

Problem

I'm trying to convert a Ruby `Date` object to a string. The format of the date is: `Sun, 15 Sep 2013` However, when I convert it to a string using `#to_s` it gives me the following: `"2013-09-15"` Instead, I want it to become: `"Sun, 15 Sep 2013"`

Original source

Related problems