DateTime.strptime with format '%m-%d-%Y %I:%M:%S %p'
require 'date'
twelve_hour_clock_time = '%m-%d-%Y %I:%M:%S %p'
puts DateTime.strptime('02-09-2007 12:30:44 AM', twelve_hour_clock_time).to_s
puts DateTime.strptime('02-09-2007 12:30:44 PM', twelve_hour_clock_time).to_s
Related examples in the same category