On this page
  1. zoneinfo
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Converting Between Timezones & Handling DST Ambiguity (fold)
  7. 2. Validating User-Supplied IANA Timezone Keys
  8. Gotchas & Boundaries
  9. Common Functions
  10. Classes & Objects
  11. Constants & Attributes

zoneinfo

Prev: zlib | Up: stdlib_module
Rel: datetime, calendar, collections, heapq, bisect
Ref: docs.python.org — zoneinfo
Tags: #public #python3 #stdlib


Import

import zoneinfo

Overview

IANA timezone database support (ZoneInfo, available_timezones) built into Python 3.9+, replacing legacy third-party pytz. Pair ZoneInfo("America/Los_Angeles") with datetime to convert UTC timestamps to real-world local wall times with accurate historical and future DST transitions.

Quick Start

from datetime import UTC, datetime
from zoneinfo import ZoneInfo

utc_now = datetime(2026, 7, 1, 18, 0, tzinfo=UTC)
local = utc_now.astimezone(ZoneInfo("America/Los_Angeles"))
assert local.hour == 11 and local.tzname() == "PDT"

Implementation Walkthrough

1. Converting Between Timezones & Handling DST Ambiguity (fold)

During autumn "fall-back" transitions, the same local wall time occurs twice; fold=0 selects the first (DST) occurrence and fold=1 selects the second (standard) occurrence:

from datetime import UTC, datetime
from zoneinfo import ZoneInfo

la = ZoneInfo("America/Los_Angeles")
first = datetime(2026, 11, 1, 1, 30, fold=0, tzinfo=la)
second = datetime(2026, 11, 1, 1, 30, fold=1, tzinfo=la)
assert first.astimezone(UTC) != second.astimezone(UTC)

2. Validating User-Supplied IANA Timezone Keys

from zoneinfo import ZoneInfo, ZoneInfoNotFoundError

def parse_tz(name: str) -> ZoneInfo:
    try:
        return ZoneInfo(name)
    except ZoneInfoNotFoundError as exc:
        raise ValueError(f"Unknown IANA timezone: {name!r}") from exc

assert parse_tz("Asia/Tokyo").key == "Asia/Tokyo"

Gotchas & Boundaries

Common Functions

Classes & Objects

Constants & Attributes

Linked from

Related notes