get all timezones and current time for each in python

You can use the pytz module to get a list of all available timezones and then use datetime module to get the current time for each timezone.

Here's an example code snippet:

main.py
import pytz
from datetime import datetime

# Get all timezones
all_timezones = pytz.all_timezones

# Loop through all timezones and get current time
for timezone in all_timezones:
    tz = pytz.timezone(timezone)
    current_time = datetime.now(tz)
    print('Current time in {}: {}'.format(timezone, current_time.time()))
323 chars
12 lines

This code will output the current time in each timezone in the format Current time in timezone_name: current_time.

gistlibby LogSnag