RFC-822 dates into Ruby dates

K

kellygreer1

Whats the right way in Ruby to pull these kind of dates apart into a
Ruby Date?

Mon, 8 Aug 2005 16:25:00 GMT

I'm working on parsing several RSS feeds and storing the data in
MySQL.

Thanks,
Kelly Greer
(e-mail address removed)
change nospam into yahoo
 
E

Eric I.

Whats the right way in Ruby to pull these kind of dates apart into a
Ruby Date?

Mon, 8 Aug 2005 16:25:00 GMT

Hi Kelly,

The DateTime class (in library 'date') can parse those strings.

====

require 'date'
d = DateTime.parse("Mon, 8 Aug 2005 16:25:00 GMT")
puts d.year
puts d.hour
puts d.zone
# and so forth... *or*
puts d.strftime "%Y %H %Z"

====

Hope that helps,

Eric

====

LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE
workshops.
Ruby Fundamentals Wkshp June 16-18 Ann Arbor, Mich.
Ready for Rails Ruby Wkshp June 23-24 Ann Arbor, Mich.
Ruby on Rails Wkshp June 25-27 Ann Arbor, Mich.
Ruby Plus Rails Combo Wkshp June 23-27 Ann Arbor, Mich
Please visit http://LearnRuby.com for all the details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top