Skip to content

Instantly share code, notes, and snippets.

@Timtech4u
Created September 24, 2018 16:09
Show Gist options
  • Select an option

  • Save Timtech4u/45effd93a418c7cfd1012e3253b71a3d to your computer and use it in GitHub Desktop.

Select an option

Save Timtech4u/45effd93a418c7cfd1012e3253b71a3d to your computer and use it in GitHub Desktop.
12hr to 24hr in Python
def timeConversion(s):
time = s
if time[-2:] == "AM" and time[:2] == "12":
return "00"+time[2:-2]
elif time[-2:] == "AM":
return time[:-2]
elif time[-2:] == "PM" and time[:2] == "12":
return time[:-2]
else:
return str(int(time[:2]) + 12) + time[2:8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment