Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using datetime, strptime(), strftime() solution in Clear category for Time Converter (12h to 24h) by H0r4c3
from datetime import datetime
def time_converter(time):
time = time.replace('a.m.', 'AM').replace('p.m.', 'PM')
in_time = datetime.strptime(time, "%I:%M %p")
out_time = datetime.strftime(in_time, "%H:%M")
print(out_time)
return out_time
if __name__ == '__main__':
print("Example:")
print(time_converter('12:30 p.m.'))
#These "asserts" using only for self-checking and not necessary for auto-testing
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!")
Feb. 16, 2022
Comments: