Python Get Current Time Example
This article is focused on how to get current time in python. In this article, we will implement a how to get current time in python using time. you can understand a concept of how to get current time in python using time. We will use how to get now time in python . Let's get started with how to get current time in python datetime.
To get both current date and time datetime.now() function of datetime module is used. This function returns the current local date and time.
So let's see bellow example:Example 1 : Get Current time()
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.417795Example 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:30Example 3 : Get Current dateTime()
import datetime currTime = datetime.datetime.now() print('Current DateTime',currTime)Output:
Current DateTime 2022-05-30 17:26:29.387683
It will help you....