Skip to content

Instantly share code, notes, and snippets.

@MuhiaKevin
Created November 11, 2019 08:35
Show Gist options
  • Save MuhiaKevin/4c28c945a38291a58811ce6ee7f12f39 to your computer and use it in GitHub Desktop.
Save MuhiaKevin/4c28c945a38291a58811ce6ee7f12f39 to your computer and use it in GitHub Desktop.
def timeConversion(stringg):
hour = stringg[:2]
mins = stringg[3:5]
seconds = stringg[6:8]
timeconvention = stringg[8:]
rest = stringg[2:8]
if int(hour) >= 1 and int(hour) <= 12 and int(mins) >= 0 and int(mins) <= 59 and int(seconds) >= 0 and int(seconds) <= 59:
if(timeconvention == 'PM'):
if(int(hour) is not 12):
hour1 = int(hour) + 12
print(str(hour1) + rest)
return str(hour1) + rest
else:
print(hour + rest)
return hour + rest
elif(timeconvention == 'AM'):
if(int(hour) is not 12):
print(hour + rest)
return hour + rest
else:
print('00'+rest)
return '00'+rest
else:
print("Time is not in correct format")
return False
timeConversion('12:05:45AM')
timeConversion('02:05:30PM')
timeConversion('08:05:25AM')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment