astimezone(tz) returns a new datetime that describes the same instant in time zone tz. The clock fields change by the difference in UTC offsets, and tzinfo becomes tz.
Internally Python converts the value to UTC with utcoffset() and then calls tz.fromutc(). This is different from replace() with tzinfo=..., which only relabels the clock reading.
datetime.astimezone() is an instance method of datetime.datetime: call it on an existing object with dot notation, such as moment.astimezone(...). Import the class first, for example from datetime import datetime.
Syntax
Pass the target zone; aware input is strongly recommended.
Gives the same instant in UTC, a common step before storing values.
moment.astimezone()
With no argument, converts to the computer's local time zone, so the result differs between machines.
If tz is the same object as moment.tzinfo, the value is returned unchanged.
Method signatures
python
datetime.astimezone(tz=None)
# tz: a tzinfo instance, or None for the local system zone
# returns: datetime aware in tz, same instant as self
Parameters
Parameter
Description
tz
Optional. The target tzinfo, such as timezone.utc. Default None uses the local system zone.
Return Value
Return Value
Description
datetime
A new aware datetime in zone tz describing the same instant.
Python Examples
Example 1 — Show a Meeting Time in Several Zones
Convert one UTC meeting to three fixed offsets and print aligned rows.
python
from datetime import datetime, timedelta, timezone
meeting = datetime(2024, 3, 15, 15, 0, tzinfo=timezone.utc)
zones = {
"New York (EDT)": timezone(timedelta(hours=-4)),
"London (GMT)": timezone(timedelta(0)),
"Kolkata (IST)": timezone(timedelta(hours=5, minutes=30)),
}
for city, zone in zones.items():
print(f"{city:15} {meeting.astimezone(zone):%H:%M}")
Output
New York (EDT) 11:00
London (GMT) 15:00
Kolkata (IST) 20:30
How It Works
One source of truth. The meeting is stored once, in UTC.
Shift by offset.astimezone() subtracts 4 hours for UTC-04:00 and adds 5 hours 30 minutes for UTC+05:30.
Aligned output.{city:15} pads names to 15 characters and :%H:%M formats each converted value.
Example 2 — Prove the Instant Does Not Change
Convert an early-morning Tokyo departure to UTC; the date moves back, but the moment is identical.