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