Answers for "converting str to 24 time only python"

3

how to convert a am pm string to 24 hrs time python

a=''
def timeConversion(s):
   if s[-2:] == "AM" :
      if s[:2] == '12':
          a = str('00' + s[2:8])
      else:
          a = s[:-2]
   else:
      if s[:2] == '12':
          a = s[:-2]
      else:
          a = str(int(s[:2]) + 12) + s[2:8]
   return a


s = '11:05:45AM'
result = timeConversion(s)
print(result)
Posted by: Guest on May-22-2020

Code answers related to "converting str to 24 time only python"

Python Answers by Framework

Browse Popular Code Answers by Language