Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
strptime.strftime solution in Clear category for Time Converter (12h to 24h) by kdim
from datetime import datetime
def time_converter(time):
t = time.replace('.', '')
return datetime.strptime(t, '%I:%M %p').strftime('%H:%M')
if __name__ == '__main__':
print("Example:")
print(time_converter('2:30 P.M.'))
assert time_converter('12:30 p.m.') == '12:30'
assert time_converter('9:00 a.m.') == '09:00'
assert time_converter('11:15 p.m.') == '23:15'
print("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 23, 2021
Comments: