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/.
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/.
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/.
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/.
Don't need a gem, the 'time' package from the standard library will do:
require 'time'
new = Time.parse(old).strftime("%T")
···
At 2009-08-31 02:09PM, "s.ross" wrote:
On Aug 31, 2009, at 10:27 AM, Alpha Blue wrote:
> 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"
$ gem install chronic
$ irb
> require 'chronic'
> Chronic.parse("3:00 PM").strftime('%H:%M:%S')
=> "15:00:00"
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous