Time Conversion

  • + 0 comments

    python

    def timeConversion(s):

    len_s = len(s)      
    if len_s !=10:
        return None
    am_or_pm = str(s)[len_s-2]
    time_24 = str(s)[:-2]
    hour = int(str(s)[:2])
    
    if am_or_pm == 'P' and  hour!=12:
        time_24 = str(hour + 12 )+str(s)[2:-2]
    else:
        if am_or_pm == 'A' and hour ==12:
            time_24 = "00"+str(s)[2:-2]
    
    return time_24