DekGenius.com
PYTHON
python current date
from datetime import date
today = date.today()
print("Today's date:", today)
get current date and time with python
import datetime
print(datetime.datetime.now())
2021-11-13 23:30:38.419951
print(datetime.date.today())
2021-11-13
python current date and time
from datetime import datetime
# datetime object containing current date and time
now = datetime.now()
print("now =", now)
#Output: now = 2021-06-25 07:58:56.550604
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print("date and time =", dt_string)
#Output: date and time = 25/06/2021 07:58:56
find out current datetime in python
from datetime import date
today = date.today()
# dd/mm/YY
d1 = today.strftime("%d/%m/%Y")
print("d1 =", d1)
# Textual month, day and year
d2 = today.strftime("%B %d, %Y")
print("d2 =", d2)
# mm/dd/y
d3 = today.strftime("%m/%d/%y")
print("d3 =", d3)
# Month abbreviation, day and year
d4 = today.strftime("%b-%d-%Y")
print("d4 =", d4)
Outputs:
d1 = 16/09/2019
d2 = September 16, 2019
d3 = 09/16/19
d4 = Sep-16-2019
pythom datetime now
>>> from datetime import datetime
>>> datetime.today().strftime('%Y-%m-%d')
'2021-01-26'
Python program to display the current date and time
import datetime
now = datetime.datetime.now()
print ("Current date and time : ")
print (now.strftime("%Y-%m-%d %H:%M:%S"))
how to get current date in python
current_date = datetime.date.today()
how to get current date and time in python
date_and_time = datetime.now()
print("The today current date and time is:- ",date_and_time)
how to get current date in python
from datetime import date
current_date = date.today()
print("today's date is ",current_date))
pythom datetime now
>>> from datetime import datetime
>>> datetime.today().strftime('%Y-%m-%d')
'2021-01-26'
Python Get current date
from datetime import date
today = date.today()
print("Current date =", today)
get the current date and time in python
from datetime import datetime
# datetime object containing current date and time
now = datetime.now()
print("now =", now)
Python Get Current Date
import datetime
date_object = datetime.date.today()
print(date_object)
Python Get Current Date and Time
import datetime
datetime_object = datetime.datetime.now()
print(datetime_object)
© 2022 Copyright:
DekGenius.com