How to Get the Current Date and Time in Python
December 29, 2022
In python, we can get the current date and time using the datetime object. In the datetime module, the now() function gives us the current local date and time.
The below example shows how to get the current date and time using the now() function:
import datetime
current_datetime=datetime.datetime.now()
print(“Current Date and Time:”,current_datetime)
current_datetime=datetime.datetime.now()
print(“Current Date and Time:”,current_datetime)
Output:
Current Date and Time: 2023-01-01 01:15:13.121315
I have an another article How to Format Date Time Data Object in Python, from where you can learn about different parameters date time formatting in Python.
In this tutorial, I tried to brief how to get the current Date and Time in Python. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page https://www.facebook.com/LearningBigDataAnalytics and stay connected.