How do I convert \"11am\" and \"10pm\" into \"11:00\" and \"22:00\"? Is there a simple way using the date and time classes?
I would first parse the string with Time#strptime and then output it with Time#strftime. This ensures a strict check with your original format as well.
Time#strptime
Time#strftime
require 'time' Time.strptime("10pm", "%I%P").strftime("%H:%M") => "22:00"