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
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X





























Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap