Convert 12 hour into 24 hour times

后端 未结 12 754
走了就别回头了
走了就别回头了 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:18

    time = raw_input().strip() # input format in hh:mm:ssAM/PM
    t_splt = time.split(':')
    if t_splt[2][2:] == 'PM' and t_splt[0] != '12':
        t_splt[0] = str(12+ int(t_splt[0]))
    elif int(t_splt[0])==12 and t_splt[2][2:] == 'AM':
        t_splt[0] = '00'
    t_splt[2] = t_splt[2][:2]
    print ':'.join(t_splt)
    

提交回复
热议问题