Python Program To Get Current Time

Python

Nicesnippets

246

16-09-2021


Hi Guys,

In this blog, I will show how to get get current time in python. We will talk about get current time using python program. In this article, we will know how to get the current time in Python.

This article will give you example of get current time using pytz module in python. I am going to learn you python get current time example.

Here i will give you three example of how to get current time in python. So let's see bellow example:

Example 1


from datetime import *

import pytz

tz = pytz.timezone('Asia/Kolkata')

datetime = datetime.now(tz)

print("INDIA time:", datetime.strftime("%H:%M:%S"))

Output:

INDIA time: 04:58:06

Example 2

from datetime import datetime

# now() method is used to

# current date & time object.

nowDateTime = datetime.now()

# strftime() method used to

# get current time.

currentTime = nowDateTime.strftime("%H:%M:%S")

print("Current Time =", currentTime)

Output:

Current Time = 04:58:06

Example 3

from datetime import datetime

# Time object containing

time = datetime.now().time()

print("Current Time is ", time)

Output:

Current Time is 04:58:06

It will help you....


Recommended Posts