Time Format Conversions

A

Alpha Blue

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
 
S

s.ross

gem install chronic

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

Does this work?
 
S

Siep Korteling

Steve said:
Oops.

$ gem install chronic
$ irb
=> "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
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top