Ive been trying to use time.strptime(string1,\'%H:%M\')
, with no success
How can I get the following:
Input Output
3:14AM -> 03:
The problem requires that you first strptime
using %I
for the 12 hour time and adding the directive %p
for AM or PM to get a time object; altogther '%I:%M%p'
. Then use strftime
to format the time object into a string:
Trials:
>>> tm = time.strptime('12:33AM', '%I:%M%p')
>>> time.strftime('%H:%M', tm)
'00:33'
>>> tm = time.strptime('9:33PM', '%H:%M%p')
>>> time.strftime('%H:%M', tm)
'09:33'
Doc reference: https://docs.python.org/2/library/time.html