CODE FOR THIS IS BELOW:
Here, in this post, we will see how can we Get Any Country Date And Time Using Python which will be something like a World clock using Python. For this, we need the datetime module and python’s timezone module i.e. pytz.
To install pytz python, type the below command in your terminal–
pip install pytz
We can print the names of all countries whose timezone is available using this module using the following code–
from datetime import datetime
import pytz
# list of desired countries
Country_Zones = ['America/New_York', 'Asia/Kolkata', 'Australia/Sydney',
'Canada/Atlantic', 'Brazil/East','Chile/EasterIsland', 'Cuba', 'Egypt',
'Europe/Amsterdam', 'Europe/Athens', 'EuropeBerlin', 'Europe/Istanbul',
'Europe/Jersey', 'Europe/London', 'Europe/Moscow', 'Europe/Paris',
'Europe/Rome', 'Hongkong', 'Iceland', 'India/n/Maldives', 'Iran', 'Israel', 'Japan', 'NZ', 'US/Alaska', 'US/Arizona', 'US/Central',
'US/East-Indiana']
country_time_zones = []
for country_time_zone in Country_Zones:
country_time_zones.append(pytz.timezone(country_time_zone))
for i in range(len(country_time_zones)):
country_time = datetime.now(country_time_zones[i])
print(f"The date of {Country_Zones[i]} is {country_time.strftime('%d-%m-%y')} and The time of {Country_Zones[i]} is {country_time.strftime('%H:%M:%S')}")
Comments
Post a Comment