Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
multiple versions solution in Clear category for Time Converter (12h to 24h) by infestum
import re
def time_converter(time: str) -> str:
time, form = time.split(' ')
hour, minute = map(int, time.split(':'))
hour = [hour % 12, hour % 12 + 12][form == 'p.m.']
return f'{hour:02}:{minute:02}'
def time_converter(time: str) -> str:
def format_time(match):
hour = int(match.group(1))
hour = [hour % 12, hour % 12 + 12][match.group(3) == 'p.m.']
return f'{hour:02}:{match.group(2)}'
return re.sub('^(\d{1,2}):(\d{2}) ([a|p].m.)', format_time, time)
Sept. 22, 2021