convert time from 12 horus to 24 hours

J

Junkone

irb(main):010:0> time=arr[1][1]
=> "11/09/2008 4:32:58 AM"

how can i convert the time to 24 hours like from 4:32:58 AM to
16:32:58
 
J

Joel VanderWerf

Junkone said:
irb(main):010:0> time=arr[1][1]
=> "11/09/2008 4:32:58 AM"

how can i convert the time to 24 hours like from 4:32:58 AM to
16:32:58

require 'time'
Time.parse("9:03 pm").strftime("%H:%M:%S")
=> "21:03:00"
Time.parse("9:03 pm").strftime("%I:%M:%S %p")
=> "09:03:00 PM"
Time.parse("21:03").strftime("%H:%M:%S")
=> "21:03:00"
Time.parse("21:03").strftime("%I:%M:%S %p")
=> "09:03:00 PM"

For details:

ri Time#strftime
 

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
474,169
Messages
2,570,920
Members
47,462
Latest member
ChanaLipsc

Latest Threads

Top