0

pytz (西部で最速のフットガン)からに移動中ですZoneInfo

timezoneAfrica/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 ですが、なぜですか?

4

0 に答える 0