Time Format Conversions

Discussion in 'Ruby' started by Alpha Blue, Aug 31, 2009.

  1. Alpha Blue

    Alpha Blue Guest

    Hi all,

    So, I'm trying to find out the best practice for converting a time
    format from the following:

    "3:00 PM"
    "10:00 PM"
    "1:00 AM"

    TO:

    "15:00:00"
    "22:00:00"
    "01:00:00"

    Can anyone help me out on what I need to do here? I'm pulling strings
    that need to be parsed and converted from > to the listings above.

    Any help would be appreciated.

    Many thanks in advance.

    JD
    --
    Posted via http://www.ruby-forum.com/.
     
    Alpha Blue, Aug 31, 2009
    #1
    1. Advertising

  2. Alpha Blue

    s.ross Guest

    gem install chronic

    Chronic.parse("3:00 PM").strftime('%H:%M:%S')
    => "15:00:00"

    Does this work?


    On Aug 31, 2009, at 10:27 AM, Alpha Blue wrote:

    > Hi all,
    >
    > So, I'm trying to find out the best practice for converting a time
    > format from the following:
    >
    > "3:00 PM"
    > "10:00 PM"
    > "1:00 AM"
    >
    > TO:
    >
    > "15:00:00"
    > "22:00:00"
    > "01:00:00"
    >
    > Can anyone help me out on what I need to do here? I'm pulling strings
    > that need to be parsed and converted from > to the listings above.
    >
    > Any help would be appreciated.
    >
    > Many thanks in advance.
    >
    > JD
    > --
    > Posted via http://www.ruby-forum.com/.
    >
     
    s.ross, Aug 31, 2009
    #2
    1. Advertising

  3. Alpha Blue

    s.ross Guest

    Oops.

    $ gem install chronic
    $ irb
    > require 'chronic'
    > Chronic.parse("3:00 PM").strftime('%H:%M:%S')

    => "15:00:00"

    On Aug 31, 2009, at 10:27 AM, Alpha Blue wrote:

    > Hi all,
    >
    > So, I'm trying to find out the best practice for converting a time
    > format from the following:
    >
    > "3:00 PM"
    > "10:00 PM"
    > "1:00 AM"
    >
    > TO:
    >
    > "15:00:00"
    > "22:00:00"
    > "01:00:00"
    >
    > Can anyone help me out on what I need to do here? I'm pulling strings
    > that need to be parsed and converted from > to the listings above.
    >
    > Any help would be appreciated.
    >
    > Many thanks in advance.
    >
    > JD
    > --
    > Posted via http://www.ruby-forum.com/.
    >
     
    s.ross, Aug 31, 2009
    #3
  4. Steve Ross wrote:
    > Oops.
    >
    > $ gem install chronic
    > $ irb
    > > require 'chronic'
    > > Chronic.parse("3:00 PM").strftime('%H:%M:%S')

    > => "15:00:00"


    The standard library 'time' parses this too:

    require 'time'
    puts Time.parse("3:00 PM").strftime('%H:%M:%S')
    => 15:00:00

    hth,

    Siep
    --
    Posted via http://www.ruby-forum.com/.
     
    Siep Korteling, Aug 31, 2009
    #4
  5. Alpha Blue

    Alpha Blue Guest

    Alpha Blue, Sep 1, 2009
    #5
    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. Trevor

    Time Conversions

    Trevor, Sep 23, 2003, in forum: HTML
    Replies:
    5
    Views:
    407
    Dave Saville
    Sep 24, 2003
  2. Fredrik Lundh

    Re: PIL and format conversions -- Noobie.

    Fredrik Lundh, Dec 14, 2004, in forum: Python
    Replies:
    0
    Views:
    468
    Fredrik Lundh
    Dec 14, 2004
  3. Replies:
    10
    Views:
    717
    Jasen Betts
    Aug 5, 2005
  4. Summu82
    Replies:
    5
    Views:
    890
    Richard Heathfield
    Jun 7, 2006
  5. Replies:
    2
    Views:
    281
    Victor Bazarov
    Oct 26, 2007
Loading...

Share This Page