Reputation: 1895
I have a string, the value of this string is an rss date. I want to convert the value of this string / the rss date into another format (MM-DD-YY HH:MM). Any ideas how to do this?
This is an extract of what I got so far...
#!/usr/bin/env ruby
require 'rss/2.0'
require 'rss/content'
[...]
date = rss.items[i].pubDate
date = #Here I want to convert the date
puts date
[...]
Upvotes: 3
Views: 1013
Reputation: 66857
Use Date.parse
to get a Date
object from a string and then Date#strftime
to format it correctly.
Here's a strftime
example:
Time.now.strftime("%m-%d-%Y %H:%M") #=> "03-27-2012 12:03
Upvotes: 3