How to Get Current Date and Time in Python

How to get current date and time in python

In This Tutorials How to Get Current date and Time in Python with an example. so we see Below as Example.

Python Program to Get Current Date and Time

Here See the python source code as example which calculate the current date and time.

from datetime import date
today = date.today()
print("Current Date = ", today)

Out Put

Current date = 2022-06-01

Get Current Date and Time in Python

In this python source code example we used datetime now to print the current date and time and used to strftime to format same.

rom 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)

Here The Output of program get current date and time in python

Current Date and Time =  2022-06-01 15:32:09.414500
Current Date and Time =  June 01, 2022 15:32:09

Leave a Comment

Verified by MonsterInsights