Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Strp/strftime solution in Clear category for Time Converter (24h to 12h) by Striga
from datetime import datetime
def time_converter(time):
t = datetime.strptime(time, '%H:%M').time()
s = t.strftime("%-I:%M %P.")
return s[:-2]+'.'+s[-2:]
if __name__ == '__main__':
assert time_converter('12:30') == '12:30 p.m.'
assert time_converter('09:00') == '9:00 a.m.'
assert time_converter('23:15') == '11:15 p.m.'
Oct. 20, 2020
Comments: