1a=''
2def timeConversion(s):
3 if s[-2:] == "AM" :
4 if s[:2] == '12':
5 a = str('00' + s[2:8])
6 else:
7 a = s[:-2]
8 else:
9 if s[:2] == '12':
10 a = s[:-2]
11 else:
12 a = str(int(s[:2]) + 12) + s[2:8]
13 return a
14
15
16s = '11:05:45AM'
17result = timeConversion(s)
18print(result)
1>>> from datetime import *
2>>> m2 = '1:35 PM'
3>>> m2 = datetime.strptime(m2, '%I:%M %p')
4>>> print(m2)
51900-01-01 13:35:00
1def timeConversion(s):
2 list = s.split(":")
3
4 if list[2].endswith("AM"):
5 if list[0] == "12":
6 list[0] = "00"
7 else:
8 if 1 <= int(list[0]) <= 11:
9 list[0] = int(list[0]) + 12
10
11 return "{}:{}:{}".format(list[0],list[1],list[2][0:2])
1time = input().strip()
2h, m, s = map(int, time[:-2].split(':'))
3p = time[-2:]
4h = h % 12 + (p.upper() == 'PM') * 12
5print(('%02d:%02d:%02d') % (h, m, s))