Python Program to Get Current Date and Time

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

from datetime import date

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

Python Program to Get Current Date and Time

In this example, we used datetime now to print the current date and time and also used the strftime to format the same.

from datetime import datetime

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

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