String
\"2011-05-19 10:30:14\"
To
Thu May 19 10:30:14 UTC 2011
How can I convert specific string to this
No need to apply anything. Just add this code at the end of variable to which date is assigned. For example
@todaydate = "2011-05-19 10:30:14"
@todaytime.to_time.strftime('%a %b %d %H:%M:%S %Z %Y')
You will get proper format as you like. You can check this at Rails Console
Loading development environment (Rails 3.0.4)
ruby-1.9.2-p136 :001 > todaytime = "2011-05-19 10:30:14"
=> "2011-05-19 10:30:14"
ruby-1.9.2-p136 :002 > todaytime
=> "2011-05-19 10:30:14"
ruby-1.9.2-p136 :003 > todaytime.to_time
=> 2011-05-19 10:30:14 UTC
ruby-1.9.2-p136 :008 > todaytime.to_time.strftime('%a %b %d %H:%M:%S %Z %Y')
=> "Thu May 19 10:30:14 UTC 2011"
Try 'date_format' gem to show date in different format.