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 Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

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