strptime, strftime solution in Clear category for Time Converter (12h to 24h) by Rcp8jzd
from time import strptime, strftime
convert the time from the 12-h format into 24-h by following the next rules:
- the output format should be 'hh:mm'
- if the output hour is less than 10 - write '0' before it. For example: '09:05'
:param time: (str) Time in a 12-hour format
:return: (str) Time in a 24-hour format
time = time.replace('a.m.', 'AM').replace('p.m.', 'PM')
time_tuple = strptime(time, '%I:%M %p')
time = strftime('%H:%M', time_tuple)
Feb. 24, 2020