How To Get Current Time in Python?


Share:
 | Published By: Admin | Published On: May 17, 2022 | Category: Python


Hi Dev,

In this quick example, let's see how to get current time in python. I want to show you how to get the current time in python using time. We will look at an example of getting the current time in python in string format. We will look at the example of how to get the current time in python DateTime. you will do the following things for python get current time in seconds.

We will look at how to get the current time in python DateTime and get the current time using pytz module in python. I am going to learn python to get the current time examples.

So let's see bellow example:

Example 1 : Get Current dateTime()
from datetime import datetime

# Time object containing
currTime = datetime.now()

print("Current Time is ", currTime)
Output:
Current Time is  2022-05-30 17:27:34.417795
Example 2 : Set timezone()
import datetime 
import pytz 
    
currTime = datetime.datetime.now(pytz.timezone('Asia/Kolkata')) 
    
# printing current time in india 
print ("The Current Time in India is : ", currTime)
Output:
The Current Time in India is :  2022-05-30 17:49:11.963509+05:30
Example 3 : Get Current time()
import datetime

currTime = datetime.datetime.now()
print('Current DateTime',currTime)
Output:
Current DateTime 2022-05-30 17:26:29.387683

It will help you....

Share: