When building Python programs that run across multiple regions, you often need to work with specific timezones.

Get Current Time in a Specific Timezone

import pytz
from datetime import datetime

# Define timezone
tz = pytz.timezone('Asia/Ho_Chi_Minh')

# Get current time in that timezone
now = datetime.now(tz)
print(now.strftime('%Y-%m-%d %H:%M:%S %Z'))
# Output: 2021-08-10 15:30:00 +07

List All Available Timezones

import pytz

for tz in pytz.all_timezones:
    print(tz)

Common Timezones

RegionTimezone String
VietnamAsia/Ho_Chi_Minh
US EasternAmerica/New_York
US PacificAmerica/Los_Angeles
UTCUTC
LondonEurope/London

Install pytz

pip install pytz