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

Python Datetime Get year, month, hour, minute, and timestamp

# Python program to demonstrate datetime object
# import datetime class
from datetime import datetime

my_datetime = datetime(1999, 3, 8, 23, 32, 12)

print("year =", my_datetime.year)
print("month =", my_datetime.month)
print("day =", my_datetime.day)
print("hour =", my_datetime.hour)
print("minute =", my_datetime.minute)
print("timestamp =", my_datetime.timestamp())
Comment

PREVIOUS NEXT
Code Example
Python :: python what does yield do 
Python :: discord.py status 
Python :: image to pdf python 
Python :: python print colored text 
Python :: file exist python 
Python :: django admin prefetch_related 
Python :: python jwt parse 
Python :: get all the keys in a dictionary python 
Python :: python print in color 
Python :: python radians to degrees 
Python :: python os checj if path exsis 
Python :: image capture from camera python 
Python :: rename multiple pandas columns with list 
Python :: pandas append dictionary to dataframe 
Python :: count similar values in list python 
Python :: how to get all links text from a website python beautifulsoup 
Python :: pandas datetime show only date 
Python :: reload all extensions discord.py 
Python :: python random string 
Python :: pandas drop empty rows 
Python :: python get index of item in 2d list 
Python :: django refresh form db 
Python :: print python path variable 
Python :: python remove read only file 
Python :: python datetime yesterday 
Python :: how to read csv file online into pandas 
Python :: python year month from date 
Python :: django proper capitalization case jinja 
Python :: pandas dataframe histogram 
Python :: python program that takes command line arguments as input and print the number of arguments 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =