You are viewing a single comment's thread. Return to all comments →
python:
` def timeConversion(s): timeOfDay = s[8:] # count last two currentTime = s[:8] # get the rest if timeOfDay == 'PM' or currentTime.startswith("12"): if timeOfDay == 'AM': return currentTime.replace(currentTime[:2], "00") if currentTime.startswith("12"): return currentTime hourBefore12 = int(currentTime[:2]) hourAfter12 = hourBefore12 + 12 return(currentTime.replace(currentTime[:2], str(hourAfter12))) else: return currentTime
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
python:
` def timeConversion(s): timeOfDay = s[8:] # count last two currentTime = s[:8] # get the rest if timeOfDay == 'PM' or currentTime.startswith("12"): if timeOfDay == 'AM': return currentTime.replace(currentTime[:2], "00") if currentTime.startswith("12"): return currentTime hourBefore12 = int(currentTime[:2]) hourAfter12 = hourBefore12 + 12 return(currentTime.replace(currentTime[:2], str(hourAfter12))) else: return currentTime