Time Conversion

  • + 0 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