Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Time Converter (24h to 12h) by ic10134
#strftime() is used to convert a time to string. The ‘time’ must be of a type struct_time
#which is a ‘tuple’ or list/array of time components. (A ‘tuple’ is a unique python structure)
#strptime accepts two parameters
#strptime is used to convert a date string to a datetime object.
#strftime() takes at most 1 argument
from datetime import datetime
def time_converter(a:str):
return datetime.strptime(a, '%H:%M').strftime('%-I:%M %p').replace('AM','a.m.').replace('PM','p.m.')
print(time_converter('12:30'))
print(time_converter('09:00'))
print(time_converter('23:15'))
July 31, 2019
Comments: