Get the Current Time in Python

In this article, we are going to learn how we can get the current time in Python. We will make use of the datetime module of Python to get the current time. Once we have the current time then we will print it in a given format of hours, minutes and seconds.

Environment & Requirements :
Python interpreter
datetime library
strftime

Get system time using Python

from datetime import datetime
x = datetime.now()
time_now = x.strftime("%H:%M:%S")
print("The Current System Time is =", time_now)

Output –
The Current System Time is = 10:32:39

Program code explanation-

1) We have imported datetime class from the datetime module.
2) We used now() method to get a datetime object containing current date and time.
3) Using datetime.strftime() method, created a string representing current time.