Python provides so many options to get the current time. Here, we will look through the various options provided.
Approach 1: Using pytz
from datetime import * import pytz time_INDIA = pytz.timezone('Asia/Kolkata') datetime = datetime.now(time_INDIA) print("INDIA time is: ", datetime.strftime("%H:%M:%S"))
Approach 2: Using Date Time object
Approach 3: Using Time
In the above program we can observe that to get the specific region current time we have used pytz module in approach 1. Python has provided datetime and time modules to get the current time. In approach 3, time.localtime() accepts the object containing the local time in seconds since epoch and returns local time.