Answers for "12 hr to 24 hour time conversion 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
1

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

>>> from datetime import *
>>> m2 = '1:35 PM'
>>> m2 = datetime.strptime(m2, '%I:%M %p')
>>> print(m2)
1900-01-01 13:35:00
Posted by: Guest on May-22-2020
0

12 hr to 24 hour time conversion python

def timeConversion(s):
    list = s.split(":")
    
    if list[2].endswith("AM"):
        if list[0] == "12":
            list[0] = "00"
    else:
        if 1 <= int(list[0]) <= 11:
            list[0] = int(list[0]) + 12
            
    return "{}:{}:{}".format(list[0],list[1],list[2][0:2])
Posted by: Guest on September-05-2021
0

12 hr to 24 hour time conversion python

time = input().strip()
h, m, s = map(int, time[:-2].split(':'))
p = time[-2:]
h = h % 12 + (p.upper() == 'PM') * 12
print(('%02d:%02d:%02d') % (h, m, s))
Posted by: Guest on May-06-2021

Code answers related to "12 hr to 24 hour time conversion python"

Python Answers by Framework

Browse Popular Code Answers by Language