Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: pandas drop empty rows 
Python :: python os.getenv not working 
Python :: python csv write add new line 
Python :: python calc days between dates 
Python :: plotly plot size 
Python :: import numpy Illegal instruction (core dumped) 
Python :: easiest way to position labels in tkinter 
Python :: get xpath of element selenium python 
Python :: how to find the calendar week python 
Python :: selenium python switch to iframe 
Python :: counter in sort python 
Python :: find location of library python linux 
Python :: python range for float 
Python :: how to print char of element in list of pytohn 
Python :: install postgres for python mac 
Python :: python convert latitude longitude to x y 
Python :: python time execution 
Python :: how to create a car game using python 
Python :: how to order ints from greatest to least python 
Python :: E: Unable to locate package python3-pip docker file 
Python :: python pandas trim values in dataframe 
Python :: pandas not is na 
Python :: how to manually click button godot 
Python :: debug flask powershel 
Python :: maximizar ventana tkinter python 
Python :: how to find common characters in two strings in python 
Python :: converting parquet to csv python 
Python :: access to numbers in classification_report - sklearn 
Python :: python plot cut off when saving 
Python :: how to read zip csv file in python 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =