Code: Select all
#UTC to "America/Winnipeg"
utc1 = datetime.datetime(2025,4,8,12,00)
utc1 = utc1.replace(tzinfo = pytz.utc)
utc2wpg = utc1.astimezone(pytz.timezone("America/Winnipeg"))
wpgb2utc = utc2wpg.astimezone(pytz.utc)
print(f"UTC Time: {utc1}")
print(f"UTC to Winnipeg Time: {utc2wpg}")
print(f"Winnipeg back to UTC Time: {wpgb2utc}")
#America/Winnipeg to UTC
wpg1 = datetime.datetime(2025,4,8,7,0)
wpg1 = wpg1.replace(tzinfo = pytz.timezone("America/Winnipeg"))
wpg2utc = wpg1.astimezone(pytz.utc)
utcb2wpg = wpg2utc.astimezone(pytz.timezone("America/Winnipeg"))
print(f"Winnipeg Time: {wpg1}")
print(f"Winnipeg to UTC Time: {wpg2utc}")
print(f"UTC back to Winnipeg Time: {utcb2wpg}")
UTC Time: 2025-04-08 12:00:00+00:00
UTC to Winnipeg Time: 2025-04-08 07:00:00-05:00
Winnipeg back to UTC Time: 2025-04-08 12:00:00+00:00
< /code>
Aber wenn Sie genau das gleiche Zeitzone ausführen, der von Winnipeg auf UTC zurückgewiesen wird, erhalten Sie diese Ausgabe: < /p>
Winnipeg Time: 2025-04-08 07:00:00-06:29
Winnipeg to UTC Time: 2025-04-08 13:29:00+00:00
UTC back to Winnipeg Time: 2025-04-08 08:29:00-05:00
< /code>
Es gibt eindeutig eine Diskrepanz in den Timezone -Conversions. Gibt es ein Problem mit meinem Code oder gibt es ein Problem mit der Konvertierung der Pytz -Bibliothek? Haben Sie den gleichen Ausgang?
Ich verwende Python 3.13