Skip to content

Instantly share code, notes, and snippets.

@tanayag
Created June 2, 2016 13:36
Show Gist options
  • Save tanayag/6ed6425ea0eebdeccf22182e4110901f to your computer and use it in GitHub Desktop.
Save tanayag/6ed6425ea0eebdeccf22182e4110901f to your computer and use it in GitHub Desktop.
AM/PM to Military Time Converter
time = raw_input('Enter Time(hh:mm:ssAM/PM): ')
AP = time[8]
if AP == 'A' and time[0:2] == '12':
ms = time.strip('AM')
p = '00'
print p + ms[2:]
elif AP == 'A':
print time.strip('AM')
elif AP == 'P' and time[0:2] == '12':
print time.strip('PM')
elif AP == 'P' and time[0:2] != '12':
mt = time.strip('PM')
x = mt[0:2]
x = int(x)
y = x + 12
y = str(y)
z = mt[2:]
mt = y + z
print mt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment