if 'AM' in time str: time_str = time_str.replace('AM', '').strip() if time_str.startswith('12'): time_str = time_str.replace('12', '00') elif 'PM' in time str: 12 hour time below AM and PM: hour, minute = map(int, time_str.split(':')) if hour = 0: return f"12:{minute:02d} AM" elif hour < 12: return f"12:{minute:02d} PM" time 12 hour = "2:30 PM" time 24 hour = to 24 hour format(time 12 hour)