+ 1
How to program a time converter
I can't seem to find the problem with my code because am still new in programming. So please I need some assistance
3 Answers
+ 5
import datetime
def timeconvert(str1):
if str1[-2:] == "AM" and str1[:2] == "12":
return "00" + str1[2:-2]
elif str1[-2:] == "AM":
return str1[:-2]
elif str1[-2:] == "PM" and str1[:2] == "12":
return str1[:-2]
else:
return str(int(str1[:2]) + 12) + str1[2:8]
dt=datetime.datetime.now()
print("Conversion Of Time ::",timeconvert(dt.strftime("%H:%M:%S")))
+ 2
Let me try to find the problem with your code. Share it here(save it on the code playground and share it's link), even if i can't find it, others might
+ 1
Vaibhav Singh don't post the answer without any explanation