krunal shah krunal shah - 4 years ago 163
Ruby Question

convert string to specific datetime format?

String

"2011-05-19 10:30:14"


To

Thu May 19 10:30:14 UTC 2011


How can I convert specific string to this Date format ?

Answer Source
require 'date'

date = DateTime.parse("2011-05-19 10:30:14")
formatted_date = date.strftime('%a %b %d %H:%M:%S %Z %Y')

See strftime() for more information about formatting dates.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download