Given a time in AM/PM format as a string, convert it to military (24-hour) time as a string.

Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock


Sample Input: 07:05:45PM
Sample Output: 19:05:45

Try not to use built in DateTime libraries.

For more information on military time, check the wiki https://en.wikipedia.org/wiki/24-hour_clock#Military_time

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def get_military_time(time):
	

Solutions:
def get_military_time(time):
	if time[-2:] == 'AM':
		hour = '00' if time[0:2] == '12' else time[0:2]
	else:
		hour = '12' if time[0:2] == '12' else str(int(time[0:2]) + 12)
	return hour + time[2:-2]


def get_military_time(time_str):
	hour = int(time_str[:2])
	pm = time_str[-2] == 'P'
	return f'{hour % 12 + 12 * pm:02}{time_str[2:-2]}'


from datetime import datetime

def get_military_time(time):
	return datetime.strptime(time, '%I:%M:%S%p').strftime('%H:%M:%S')


def get_military_time(time):
	h = int(time[:2])
	if time.endswith('AM'):
		h = h % 12
	elif h < 12:
		h += 12
	return f'{h:02d}{time[2:8]}'


def get_military_time(s):
	return '%02d:%02d:%02d' % (int(s[:2]) % 12 + 12 * (s[-2] != 'A'), int(s[3:5]), int(s[6:8]))


def get_military_time(stg):
	(h, ms, ap) = (int(stg[:2]) % 12, stg[2:8], stg[8:])
	return f"{h + (12 if ap == 'PM' else 0):02d}{ms}"


get_military_time = lambda t: '%02d%s' % (int(t[:2]) % 12 + 12 * (t[-2] > 'A'), t[2:-2])


def get_military_time(s):
	delta = 12 * s.endswith('PM')
	(h, m, s) = s[:-2].split(':')
	hour = int(h) + delta
	return '{:02}:{}:{}'.format(12 if hour == 24 else 0 if hour == 12 else hour, m, s)


def get_military_time(t):
	modt = t[:-2]
	if '12' == t[:2]:
		modt = '00' + modt[2:]
	if 'PM' == t[-2:]:
		modt = str(12 + int(modt[:2])) + modt[2:]
	return modt


def get_military_time(_s):
	if 'A' in _s and _s.startswith('12'):
		return '00' + _s[2:-2]
	if 'P' in _s and (not _s.startswith('12')):
		return str(int(_s[:2]) + 12) + _s[2:-2]
	return _s[:-2]