Sub topic 8
Converting between time zones
This chapter assumes you can already build aware datetimes with ZoneInfo. It also assumes you know that a naive datetime has no tzinfo and an aware one does. Here you will learn how astimezone moves a moment between zones, and which mistakes make the result wrong.
One moment, many labels
A moment in time exists once. New York, UTC, and Tokyo only differ in how they write it down. Converting a time zone changes the label (the wall-clock fields and the offset). It does not change the moment.
The method that does this is datetime.astimezone(tz). It returns a new aware datetime that represents the same instant, expressed in tz.
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
meeting = datetime(2026, 11, 26, 9, 0, tzinfo=ZoneInfo("America/New_York"))
print(meeting.astimezone(timezone.utc))
print(meeting.astimezone(ZoneInfo("Asia/Tokyo")))This prints:
2026-11-26 14:00:00+00:00
2026-11-26 23:00:00+09:00New York is on standard time in late November, at UTC-5. So 09:00 there is 14:00 UTC. Tokyo is at UTC+9, so the same instant reads 23:00.
Converting to several zones
Because astimezone returns a new object, you can start from one datetime and fan out to many zones. The original is never changed.
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
event = datetime(2026, 11, 26, 14, 0, tzinfo=timezone.utc)
for name in ["Europe/London", "Asia/Kolkata", "Australia/Sydney"]:
local = event.astimezone(ZoneInfo(name))
print(f"{name:18} {local.isoformat()}")The output is:
Europe/London 2026-11-26T14:00:00+00:00
Asia/Kolkata 2026-11-26T19:30:00+05:30
Australia/Sydney 2026-11-27T01:00:00+11:00Two details show up here. Kolkata's offset is not a whole number of hours. Sydney's local date has moved to the next day. Never assume a conversion keeps the date or shifts by whole hours.
astimezone versus replace
The most common error is using replace(tzinfo=...) when you mean to convert. replace keeps the clock fields and swaps the label. That describes a different instant.
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
utc_time = datetime(2026, 11, 26, 14, 0, tzinfo=timezone.utc)
tokyo = ZoneInfo("Asia/Tokyo")
converted = utc_time.astimezone(tokyo)
relabelled = utc_time.replace(tzinfo=tokyo)
print(converted)
print(relabelled)
print(converted == relabelled)The output is:
2026-11-26 23:00:00+09:00
2026-11-26 14:00:00+09:00
FalseThe relabelled value is nine hours off from the original instant.
Use each method for its own job:
| Situation | Method |
|---|---|
| The datetime is aware and you want the same instant in another zone | `astimezone(tz)` |
| The datetime is naive and you know which zone its fields were written in | `replace(tzinfo=tz)` |
The second row is how you attach a zone to a naive value once. After that, convert with astimezone.
Converting through UTC
Comparing and subtracting aware datetimes already works across zones. Python compares the underlying instants, so you do not need to convert first.
from datetime import datetime
from zoneinfo import ZoneInfo
ny = datetime(2026, 11, 26, 9, 0, tzinfo=ZoneInfo("America/New_York"))
tokyo = datetime(2026, 11, 26, 23, 0, tzinfo=ZoneInfo("Asia/Tokyo"))
print(ny == tokyo)
print(tokyo - ny)This prints True and 0:00:00, because both values name the same instant. Convert only when you need to display a time or to read a local field such as the date or the hour.
Common errors
- Converting a naive value. Attach a zone first with
replace(tzinfo=...), or build it aware from the start. - Using fixed offsets for named places.
timezone(timedelta(hours=-5))cannot know about daylight saving. UseZoneInfo("America/New_York")for a real location. - Misspelled zone keys.
ZoneInfo("America/NewYork")raisesZoneInfoNotFoundError. Zone keys are case-sensitive IANA names such asAmerica/New_York. - Reading the date after converting. The calendar date can change. Take
.date()from the converted value, not the original.
Exercise
A server stores datetime(2026, 11, 26, 14, 0, tzinfo=timezone.utc). A teammate writes stored.replace(tzinfo=ZoneInfo("Asia/Tokyo")) to show it in Tokyo time. What is wrong, and what is the correct call?
Show answer
replace keeps 14:00 and only changes the label, so the result is 14:00+09:00, which is a different instant nine hours earlier than the stored one. The correct call is stored.astimezone(ZoneInfo("Asia/Tokyo")), which gives 2026-11-26 23:00:00+09:00.
Exercise
What does datetime(2026, 11, 26, 9, 0).astimezone(timezone.utc) do, and why is it risky?
Show answer
The datetime is naive, so Python treats it as system local time and converts from that. The result depends on the machine's configured zone, so the same code can give different answers on different computers. Make the datetime aware first.