33: Python Program to find the current time in India (IST)

Question 33: Write a program in Python to find the current time in India - that is Indian Standard Time - IST


Solution:
import datetime
import pytz

current_time_utc = datetime.datetime.now(pytz.utc)

ist_timezone = pytz.timezone('Asia/Kolkata')
india_ist_time = current_time_utc.astimezone(ist_timezone)

ist_time_formatted = india_ist_time.strftime('%d/%m/%Y %H:%M:%S %Z%z')

print('Current time in India (IST):', ist_time_formatted)
Output:

Current time in India (IST): 11/07/2023 13:05:21 IST+0530

Python Program to get current time in IST - Code2care

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!