zoneinfo — IANA 时区支持

Added in version 3.9.

源代码: Lib/zoneinfo


The zoneinfo module provides a concrete time zone implementation to support the IANA time zone database as originally specified in PEP 615 。默认情况下, zoneinfo uses the system’s time zone data if available; if no system time zone data is available, the library will fall back to using the first-party tzdata package available on PyPI.

另请参阅

模块: datetime

Provides the time and datetime types with which the ZoneInfo class is designed to be used.

tzdata

First-party package maintained by the CPython core developers to supply time zone data via PyPI.

可用性 :非 WASI。

This module does not work or is not available on WebAssembly. See WebAssembly 平台 了解更多信息。

使用 ZoneInfo

ZoneInfo is a concrete implementation of the datetime.tzinfo abstract base class, and is intended to be attached to tzinfo , either via the constructor, the datetime.replace method or datetime.astimezone :

>>> from zoneinfo import ZoneInfo
>>> from datetime import datetime, timedelta
>>> dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles"))
>>> print(dt)
2020-10-31 12:00:00-07:00
>>> dt.tzname()
'PDT'