Convert 12 hour into 24 hour times

后端 未结 12 750
走了就别回头了
走了就别回头了 2020-12-31 08:17

I\'m trying to convert times from 12 hour times into 24 hour times...

Automatic Example times:

06:35  ## Morning
11:35  ## Morning (If m2 is anywhe         


        
12条回答
  •  悲哀的现实
    2020-12-31 08:33

    def timeConversion(s):
        if "PM" in s:
            s=s.replace("PM"," ")
            t= s.split(":")
            if t[0] != '12':
                t[0]=str(int(t[0])+12)
                s= (":").join(t)
            return s
        else:
            s = s.replace("AM"," ")
            t= s.split(":")
            if t[0] == '12':
                t[0]='00'
                s= (":").join(t)
            return s
    

提交回复
热议问题