Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to convert 24 hours to 12 hours in python

from datetime import datetime
d = datetime.strptime("10:30", "%H:%M")
print(d.strftime("%I:%M %p")) # outputs '10:30 AM'
d = datetime.strptime("22:30", "%H:%M")
print(d.strftime("%I:%M %p")) # outputs'10:30 PM'
Comment

python convert 12 hour time to 24 hour

df['Time'] = pd.to_datetime(df['Time'], format='%I:%M:%S %p').dt.strftime('%H:%M:%S')
print (df)
       Time
1  17:21:26
2  17:21:58
3  17:22:22
4  17:22:36
5  19:18:16
Comment

PREVIOUS NEXT
Code Example
Python :: python date from yy/mm/dd to yy-mm-dd 
Python :: how to add subplots for histogram in pandas 
Python :: ssl unverified certificate python 
Python :: python conditional assignment 
Python :: how to delete the last item in a list python 
Python :: euclidean distance python 
Python :: python list to string with spaces 
Python :: plotly scatter markers size 
Python :: python write list to text file 
Python :: hide particular attribute in django admin 
Python :: selenium refresh till the element appears python 
Python :: tkinter text in canvas 
Python :: how to clear a text file in python 
Python :: wait() in python tkinter 
Python :: take two numbers as inout in single line in python 
Python :: identify prime numbers python 
Python :: install biopython in windows 
Python :: how to stop running code in python 
Python :: number of columns with no missing values 
Python :: Test Speed internet using Python 
Python :: random with probability python 
Python :: Writing Bytes to a File in python 
Python :: python intersection of two lists 
Python :: python ndarray string array into int 
Python :: python global site packages 
Python :: show aruco marker axis opencv python 
Python :: save strings with numpy savetext 
Python :: python download video from url requests 
Python :: python search string for word 
Python :: coco.py 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =