Time Conversion

  • + 0 comments
    # two options:
    
    def timeConversion(s):
        from datetime import datetime
        in_time = datetime.strptime(s, "%I:%M:%S%p")
        out_time = datetime.strftime(in_time, "%H:%M:%S")
        return out_time
    
    def timeConversion(s):
        if s[-2:] == 'AM':
            if s[:2] == '12':
                res = '00' + s[2:-2]
            else:
                res =  s[:-2]
        else:
            if s[:2] == '12':
                res = '12' + s[2:-2]
            else:
                res = f'{int(s[:2]) + 12}{s[2: -2]}'
        return res