How to Get Current Time in Python?

By Hardik Savani October 30, 2023 Category : Python

In this tute, we will discuss python get current time. We will look at example of python get current time in hh mm ss. you will learn python how get current time. I’m going to show you about how to get current time in python.

In this post, i will give you three examples to getting current time in python. we will use datetime module to get current time from date. so let's see following examples with output:

Example 1:

main.py

from datetime import datetime
  
today = datetime.now()
  
currentTime = today.strftime("%H:%M:%S")
print("Current Time:", currentTime);

Output:

Current Time: 09:19:25

Example 2:

main.py

from datetime import datetime
       
currentTime = datetime.now().time()
print("Current Time:", currentTime);

Output:

Current Time: 09:19:25.514195

I hope it can help you...

Tags :
Shares