RFC-822 dates into Ruby dates

Discussion in 'Ruby' started by kellygreer1, Jun 8, 2008.

  1. kellygreer1

    kellygreer1 Guest

    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

    change nospam into yahoo
    kellygreer1, Jun 8, 2008
    #1
    1. Advertising

  2. kellygreer1

    Eric I. Guest

    On Jun 8, 6:12 pm, kellygreer1 <> wrote:
    > 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.
    Eric I., Jun 8, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Florian Lindner

    RFC 822 continuations

    Florian Lindner, May 2, 2006, in forum: Python
    Replies:
    2
    Views:
    283
  2. sorci-engine

    Problematical RFC 822 date-time value

    sorci-engine, Jun 7, 2007, in forum: XML
    Replies:
    3
    Views:
    752
    sorci-engine
    Jun 10, 2007
  3. Jure Sah
    Replies:
    2
    Views:
    969
    Peter Flynn
    Mar 9, 2009
  4. Bob Kline
    Replies:
    8
    Views:
    271
    Carl Banks
    Jan 21, 2011
  5. Ivan Shmakov
    Replies:
    3
    Views:
    1,140
    Kari Hurtta
    Feb 13, 2012
Loading...

Share This Page