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

Solutions on MaxInterview for how to convert a am pm string to 24 hrs time python by the best coders in the world

showing results for - "how to convert a am pm string to 24 hrs time python"
Christian
22 Aug 2017
1a=''
2def timeConversion(s):
3   if s[-2:] == "AM" :
4      if s[:2] == '12':
5          a = str('00' + s[2:8])
6      else:
7          a = s[:-2]
8   else:
9      if s[:2] == '12':
10          a = s[:-2]
11      else:
12          a = str(int(s[:2]) + 12) + s[2:8]
13   return a
14
15
16s = '11:05:45AM'
17result = timeConversion(s)
18print(result)
Thimeo
06 Feb 2020
1>>> from datetime import *
2>>> m2 = '1:35 PM'
3>>> m2 = datetime.strptime(m2, '%I:%M %p')
4>>> print(m2)
51900-01-01 13:35:00
queries leading to this page
how to convert a am pm string to 24 hrs time pythonconvert str into 24 hr time pythinpython convert 12 hour time to 24 hourchanging time from 12 hour to 24 hour representation pandas12 hour to 24 hour pythonpython time format 12 hour am pmtake input in python in form of hr min am 2fpmhow to convert am pm in pythonconvert into 24 hr time pythinconvert date string to 24 hour time pythonpython 12 hour to 24 hourconverting to military time in pythonconvert time in 24 hour format in pythomconvert 12 hour datetime to 24 hour datetime pythonconverting str to 24 time only pythonconvert 12 hour to 24 hour in pythonconvert 12 hrs to 24 hrs in python12 hour format to 24 hour format in pythonconvert 12hr to 24hr in pythonconvert given data points in military time to 24 hours format in pythonsqlalchmy 12 hours convert to 24 hoursturning 24 hr time to int in pythonconvert 12 hour clock to 24 hour clock pythonhow to convert 12hr to 24hr in pythonconvert 12 hr to 24 hr in pythonpython time format 12 hourconvert from 12 hours to 24 pythonpython convert 12 hour to 24 hour lambdagiven a time in 12 hour am 2fpm format convert it to military 2824 hour 29 time in pythonconvert time from 24 hour clock to 12 hour clock format python12 hour clock to 24 hour clock in pythonconvert 24 hr to 12 hr pythonconvert 12 hour to 24 hour decimal in pythonconvert to 24 hour format in pythonpython convert time to 24 hourhow to convert am pm to 24 hours pythonpython 24 hour to am pmconvert 24 hour time to am pm pythonhow to get time in military py12 hour format python code24ours date time convert into am pm pythonhow to convert into 24 hour format in pythonconvert am pm to 24 hour pythonconvert 12 hour time to 24 hour pythonconvert 12 hour clock to 24 hour pythonpython code for 24 hpur format to 12 hour formatpython convert datetime am pm to 24 hourhow to convert time format in pythonconvert 2812 29 to 12 in pythonconvert 12 hour to 24 hour pythonpython 24 hour function convert am to 24hr python timeconvert 12 hr to 24 hr pythoncompare 12 and 24 hour time in pythondatetime to 24 hr time pythonconvert 12 to 24 hour time pythonpython code for 24 hours formathow to convert 24 hours to minutes in dataframe python12 hr to 24 hour time conversion pythonbuilt in function for time conversion from am 2fpm into 24 hour format in python conver 12 hour time to 24 pythonconvert datetime 12 to 24 hour time pythonturning 24 hour time to int in pythonconvert 12 hour to 24 hou pythontime conversion in pythonconvert 12h to 24h python12hr to 24hr pythonpython convert 12 hr clock to 24 hrhow to convert 12 hors format to 24 hours in pythonsqlalchemy convert date time formt in 24 hourspython program to convert time from 12 hour to 24 hour formatconverting str to 24 time pythincahnge 24 hour time python timedatetime python 12hr to 24hrconvert 12 hour format to 24 hour format in pythonconvert a string to time python 24 hour format00 12 format of hour in pythoncan we convert am to pm in pythonhow to work out time right now python 24 hour clockhow to convert 12 hours to 24 hours in pythonchange integer to 24 hour time pythonrailway time converter pythonchanging the time from 12 hour into 24 hour in pandasconvert am 2fpm to 24 hour in pythonconvert railway time to normal time pythonconversion 24 hours clock to 12 hour in pythonhow to convert a am pm string to 24 hrs time python