Time Conversion

  • + 0 comments

    A python 3 solution

    def timeConversion(s):
        # Write your code here
        hh = int(s[0:2])
        mm = s[3:5] 
        ss = s[6:8]
        period= s[8:9]
        if period == "P" and hh<12:
            hh +=12
        elif period =="A" and hh == 12 :
            hh = 0
        hour = f"{hh:02d}" if hh<10 else str(hh)
        return f"{hour}:{mm}:{ss}"