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"
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With