我正在从pytz
(西部最快的足枪)迁移到ZoneInfo
.
我正在使用 timezone 进行测试Africa/Johannesburg
,即 GMT+2(注意:GMT = UTC)。我希望以下结果会产生相同的结果,但是 GMT+2 是不正确的:
由于我使用的是 python 3.8,因此我必须使用zoneinfo
.
>> from backports import zoneinfo
>>> jhb_tz = zoneinfo.ZoneInfo("Africa/Johannesburg")
>>> gmt2_tz = zoneinfo.ZoneInfo("Etc/GMT+2")
>>> from datetime import datetime, timezone
>>> UTC = timezone.UTC
>>> now = datetime.now(UTC)
>>> now
datetime.datetime(2022, 1, 1, 14, 50, 3, 305445, tzinfo=datetime.timezone.utc)
>>> now.astimezone(jhb_tz) # Is correct, i.e. UTC+2
datetime.datetime(2022, 1, 1, 16, 50, 3, 305445, tzinfo=backports.zoneinfo.ZoneInfo(key='Africa/Johannesburg'))
>>> now.astimezone(gmt2_tz) # Incorrect, i.e. UTC-2
datetime.datetime(2022, 1, 1, 12, 50, 3, 305445, tzinfo=backports.zoneinfo.ZoneInfo(key='Etc/GMT+2'))
GMT+2 实际上是 GMT-2 而不是 GMT+2,这是为什么呢?