Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to get the current date hour minute month year in python

########################################################################
import datetime
now = datetime.datetime.now()
print(now.year, now.month, now.day, now.hour, now.minute, now.second)
########################################################################
from datetime import *
now = datetime.now()
print(now.year, now.month, now.day, now.hour, now.minute, now.second)
########################################################################
Comment

python year month day hour minute second

import datetime
date = '2021-05-21 11:22:03'
datem = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
print(datem.day)        # 25
print(datem.month)      # 5
print(datem.year)       # 2021
print(datem.hour)       # 11
print(datem.minute)     # 22
print(datem.second)     # 3
Comment

get month day year 12 hour time format python

import time

# get current time
date_time = time.strftime("%b %d, %Y %-I%p")

#the above outputs: May 27, 2021 7PM
Comment

PREVIOUS NEXT
Code Example
Python :: python minute from datetime 
Python :: decode url python 
Python :: convert dictionary keys to int python 
Python :: requirements file generate django 
Python :: text adventure in python 
Python :: python import all words 
Python :: pandas plot disable legend 
Python :: how to change voice of pyttsx3 
Python :: redirect to the same page django 
Python :: how to change button background color while clicked tkinter python 
Python :: python parsing meaning 
Python :: how to rotate x axis labels in subplots 
Python :: how to do key sensing in python 
Python :: python random email generator 
Python :: sparksession pyspark 
Python :: loop through groupby pandas 
Python :: get all classes from css file using python 
Python :: csv from string python 
Python :: flash messages django 
Python :: dataframe show to semicolon python 
Python :: django and react url conflict 
Python :: random int in python 3 
Python :: python httpserver 
Python :: calculator in one line in python 
Python :: python save string to text 
Python :: minimum and max value in all columns pandas 
Python :: day difference between two dates in python 
Python :: length ofarray in ptyon 
Python :: how to make a PKCS8 RSA signature in python 
Python :: choose random index from list python 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =