Python datetime.astimezone() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
datetime method

Definition

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.

python
converted = moment.astimezone(tz)
in_utc = moment.astimezone(timezone.utc)
CallWhat it does
datetime(2024, 3, 15, 15, 0, tzinfo=timezone.utc).astimezone(timezone(timedelta(hours=-4)))Returns datetime.datetime(2024, 3, 15, 11, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000))).
moment.astimezone(timezone.utc)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

ParameterDescription
tzOptional. The target tzinfo, such as timezone.utc. Default None uses the local system zone.

Return Value

Return ValueDescription
datetimeA 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}")

How It Works

  1. One source of truth. The meeting is stored once, in UTC.
  2. Shift by offset. astimezone() subtracts 4 hours for UTC-04:00 and adds 5 hours 30 minutes for UTC+05:30.
  3. 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.

python
from datetime import datetime, timedelta, timezone

tokyo = timezone(timedelta(hours=9))
departure = datetime(2025, 1, 1, 6, 30, tzinfo=tokyo)
in_utc = departure.astimezone(timezone.utc)

print(in_utc)
print(departure == in_utc)
print(departure.timestamp() == in_utc.timestamp())
print(in_utc.date() < departure.date())

How It Works

  1. Back across midnight. 06:30 at UTC+09:00 is 21:30 UTC on the previous day, even in the previous year.
  2. Equal instants. Aware datetimes compare by instant, so == is True.
  3. Same timestamp. timestamp() gives one number for both.
  4. Dates differ. Only the wall-clock date changed, which is why reports must pick a zone.

Example 3 — Convert into a Custom Zone with Summer Time

Define a toy zone at UTC+02:00 with one extra hour from June to August, then convert two UTC noons into it.

python
from datetime import datetime, timedelta, timezone, tzinfo


class Coastal(tzinfo):
    """Toy zone: UTC+2, plus one hour of DST from June to August."""

    def utcoffset(self, dt):
        return timedelta(hours=2) + self.dst(dt)

    def dst(self, dt):
        return timedelta(hours=1) if 6 <= dt.month <= 8 else timedelta(0)

    def tzname(self, dt):
        return "CZST" if self.dst(dt) else "CZT"


coastal = Coastal()
for month in (1, 7):
    moment = datetime(2024, month, 10, 12, 0, tzinfo=timezone.utc).astimezone(coastal)
    print(moment.strftime("%Y-%m-%d %H:%M"), moment.tzname(), moment.utcoffset())

How It Works

  1. Three required methods. The subclass answers utcoffset(), dst(), and tzname() for any datetime.
  2. Default fromutc(). tzinfo.fromutc() uses those answers to turn UTC noon into local time.
  3. Winter vs summer. January gets +2 hours (14:00) and July gets +3 hours (15:00) with the summer name.
  4. Real zones. For actual places, the zoneinfo module (Python 3.9+, plus tzdata on Windows) provides tzinfo objects with official rules.

Frequently Asked Questions

Make it aware, then call moment.astimezone(tz), for example moment.astimezone(timezone.utc).
astimezone() converts the clock time so the instant stays the same; replace() keeps the clock time and changes the zone label.
It converts to the local time zone of the computer running the code.
Yes since Python 3.6, but Python assumes the naive value is local system time. Attach the correct zone first to avoid surprises.
Use zoneinfo.ZoneInfo("Europe/London") on Python 3.9+; on Windows install the tzdata package first.

Next: datetime.combine()

Classmethod: join a date and a time into one datetime, with an optional tzinfo.

combine() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful