World Clock Tutorial - Python

World Clock Tutorial - Python

🌍 World Clock Tutorial Using Python

Objective: Learn how to build a simple world clock that shows the current time in different cities using Python.

Open your terminal or command prompt and run:

pip install pytz
from datetime import datetime
import pytz

# List of cities with their time zones
cities = {
    'New York': 'America/New_York',
    'London': 'Europe/London',
    'Paris': 'Europe/Paris',
    'Tokyo': 'Asia/Tokyo',
    'Sydney': 'Australia/Sydney',
    'Mumbai': 'Asia/Kolkata'
}

print("🌍 World Clock\\n")
for city, timezone in cities.items():
    tz = pytz.timezone(timezone)
    city_time = datetime.now(tz)
    print(f"{city:10s} ➤ {city_time.strftime('%Y-%m-%d %H:%M:%S')}")
  
  • Try adding more cities and explore different timezones from the pytz library.
  • Build a GUI version using tkinter for practice.
  • Understand the impact of daylight saving time and how pytz handles it.

Comments