Python Program to Get Current Date and Time

Write a Python program to get current date and time with an example. For example, in Python, we have a datetime module to work with or print the current date and time. Here, it will display the current date.

from datetime import date

today = date.today()
print("Current Date = ", today)
Current Date =  2021-11-06

In the Python example, we used datetime now to print the current date and time. Also used the strftime to format the date and time.

from datetime import datetime

today = datetime.now()
print("Current Date and Time = ", today)

# Formatting Date and Time
dt = today.strftime("%B %d, %Y %H:%M:%S")
print("Current Date and Time = ", dt)
Python Program to Get Current Date and Time 2