zoneinfo.ZoneInfo and ZoneInfoNotFoundError
ZoneInfo(key)
exception ZoneInfoNotFoundErrorShow a missing key, convert a fixed UTC moment into America/New_York, and print both fold values at the 2026 fallback.
| Parameter | Description |
|---|---|
key | An IANA time zone name such as America/New_York or UTC. It is not a fixed offset like UTC+8; use datetime.timezone for those, as on the datetime page. |
Returns: A ZoneInfo tzinfo instance when the key exists.
Raises
ZoneInfoNotFoundError— Raised when the key is absent from the available IANA data, as with Not/AZone. It is a subclass of KeyError.
- The America/New_York offsets were measured with Python 3.13.12 and tzdata 2026.2. If that zone is missing where you run the example, ZoneInfoNotFoundError is raised instead of the conversion lines.
from datetime import datetime
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
try:
tz = ZoneInfo("Not/AZone")
print("unexpected", tz)
except ZoneInfoNotFoundError as exc:
print(type(exc).__name__)
ny = ZoneInfo("America/New_York")
moment = datetime(2026, 11, 21, 15, 30, tzinfo=ZoneInfo("UTC"))
print(moment.astimezone(ny).isoformat())
first = datetime(2026, 11, 1, 1, 30, tzinfo=ny, fold=0)
second = datetime(2026, 11, 1, 1, 30, tzinfo=ny, fold=1)
print(first.isoformat(), first.fold)
print(second.isoformat(), second.fold)
print(first == second)Expected output
ZoneInfoNotFoundError
2026-11-21T10:30:00-05:00
2026-11-01T01:30:00-04:00 0
2026-11-01T01:30:00-05:00 1
TrueRelated: datetime (aware values and UTC), time (UTC timestamps)