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 :: como calcular el rango en python 
Python :: tkinter yt downloader with resolution 
Python :: how to use list compression with conditional formatting 
Python :: gnome-terminal stopped executing after python 3.6 is installed 
Python :: flatten a list of lists python 
Python :: how to upgrade pip 
Shell :: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation 
Shell :: add-apt-repository command not found 
Shell :: ubuntu XAMPP Starting Apache...fail 
Shell :: check supervisord status 
Shell :: postgres stop linux 
Shell :: update google chrome command ubuntu 
Shell :: how to restart nginx 
Shell :: uninstall wps office ubuntu 
Shell :: git clean cache 
Shell :: install openzeppline 
Shell :: conda install ipywidgets 
Shell :: restart rabbitmq service linux 
Shell :: undo git 
Shell :: nginx stop commands 
Shell :: mac pip command not found 
Shell :: beautifulsoup python 
Shell :: how to change hostname in ubuntu 
Shell :: Could not build wheels for pygalmesh which use PEP 517 and cannot be installed directly 
Shell :: tmux for ubuntu 
Shell :: check if service in running to a port in linux 
Shell :: laravel migrate rollback specific file 
Shell :: install pprint python 
Shell :: cannot find lock /var/lib/dpkg/lock-frontend 
Shell :: install google chrome ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =