Convert RSS pubDate Date to MM-DD-YY HH: MM

I have a string, the value of this string is rss date. I want to convert the value of this rss string / date to a different format (MM-DD-YY HH: MM). Any ideas how to do this?

This is an excerpt from what I have received 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

[...]

      

+3


source to share


1 answer


Use Date.parse

to get an object Date

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

      

+3


source







All Articles