In this tutorial, you’ll learn how to work with timezones in Python. Timezones matter as soon as your program deals with users, servers, or events in more than one place, for example a meeting scheduler, a flight booking site, or logs collected from servers around the world.
This article is part of a series on Python Date and Time.
After reading this article, you’ll learn:
- The difference between timezone-naive and timezone-aware datetimes.
- How to create a timezone-aware datetime using the built-in zoneinfo module and the timezone class.
- How to get the current time in a different timezone.
- How to get the timezone name, UTC offset, and DST offset of a datetime.
- How to convert a datetime from one timezone to another.
- How daylight saving time affects calculations, and how to avoid common mistakes.
- How to use the third-party pytz library, which you’ll still see in older code.
Table of contents
What is timezone in Python?
A timezone is a region of the world that uses the same standard time. Each timezone is described by its offset from UTC (Coordinated Universal Time), the world’s reference time. For example, India is 5 hours 30 minutes ahead of UTC, written as UTC+05:30.
Many timezones also use daylight saving time (DST): they move their clocks forward by an hour in summer. So the offset of a place can change during the year. For example, US Central Time is UTC-6 in winter (CST) and UTC-5 in summer (CDT).
| UTC Offset | Abbreviation | Timezone name |
|---|---|---|
| UTC+09:00 | JST (no DST) | Asia/Tokyo |
| UTC+05:30 | IST (no DST) | Asia/Kolkata |
| UTC+00:00 / UTC+01:00 | GMT in winter / BST in summer | Europe/London |
| UTC-06:00 / UTC-05:00 | CST in winter / CDT in summer | America/Chicago |
| UTC-10:00 | HST (no DST) | Pacific/Honolulu |
In Python, timezone information is stored in a tzinfo object attached to a datetime. tzinfo is an abstract base class, so you don’t use it directly. Instead, you use one of its implementations:
datetime.timezone: a fixed offset from UTC, such as UTC or UTC+09:00. It doesn’t know about DST.zoneinfo.ZoneInfo(Python 3.9+): a real-world timezone from the IANA database, such as'America/Chicago'. It applies DST rules automatically. This is the recommended choice.pytz: a third-party library that was the standard before Python 3.9.
Note: On Windows, run pip install tzdata once so zoneinfo can find the timezone data. Linux and macOS already include it.
Create Timezone Aware Datetime Object
A datetime object can be naive or aware:
- A naive datetime has no timezone information (its
tzinfoisNone).datetime.now()anddatetime(2026, 7, 1, 9, 0)both create naive datetimes. Python doesn’t know which place’s 9:00 they mean. - An aware datetime has a
tzinfo, so it represents one exact moment in time.
Follow the steps below to create a timezone-aware datetime object in Python:
- Import
ZoneInfowithfrom zoneinfo import ZoneInfo. - Create a timezone object with its name, for example
ZoneInfo('America/Chicago'). - Pass it to
datetime.now(tz)for the current time, or as thetzinfoargument when you build a specific datetime.

Example:
Output:
Naive: 2026-07-01 09:00:00 | tzinfo: None UTC aware: 2026-07-01 09:00:00+00:00 US Central aware: 2026-07-01 09:00:00-05:00
- The UTC datetime ends with the offset +00:00.
- The US Central datetime ends with -05:00, because on 1 July Chicago is on daylight saving time (CDT). In January, the same code would show -06:00.
For the current time, pass the timezone to datetime.now():
Output:
Local naive: 2026-12-01 12:01:24.844050 UTC: 2026-12-01 06:31:24.844072+00:00 US Central: 2026-12-01 00:31:24.844193-06:00
Your output will show the time when you run the program. Refer to list all timezones in Python if you don’t know the exact name of the timezone you need.
Make an Existing Naive Datetime Timezone Aware
If you already have a naive datetime and you know which timezone it belongs to, attach the timezone with replace(tzinfo=...). This keeps the date and time the same and only adds the timezone:
Output:
Naive: 2026-06-15 08:45:17 Aware: 2026-06-15 08:45:17+02:00
Note: replace() returns a new datetime and leaves the original unchanged. It doesn’t convert the time. To convert a time into another timezone, use astimezone(), explained below.
Format a Datetime to Show the Timezone Name
Use the %Z directive of strftime() to show the timezone abbreviation, and %z to show the UTC offset:
Output:
Formatted DateTime in IST: 2026-07-08 17:53:23 IST +0530
Here, IST is the timezone abbreviation and +0530 is the offset from UTC.
Create TimeZone Aware Datetime Object Using timezone class
The datetime module’s timezone class (a subclass of tzinfo) represents a fixed offset from UTC. It needs no extra data, so it’s handy for UTC, or when you only know the offset and not the place.
Syntax:
datetime.timezone(offset, name=None)Code language: Python (python)
offset: a timedelta giving the difference from UTC. It must be strictly between-timedelta(hours=24)andtimedelta(hours=24).name: an optional name, returned bytzname().
Example:
Output:
UTC DateTime: 2026-07-01 12:00:00+00:00 In JST: 2026-07-01 21:00:00+09:00 JST True
Both datetimes represent the same moment, so they compare as equal even though the clock times are different.
Note: A fixed offset doesn’t change for daylight saving time. Use timezone for UTC or fixed offsets, and ZoneInfo for real places like 'Europe/London'.
Get Current Time in Different Timezone
To get the current date and time in any timezone, pass a ZoneInfo object to datetime.now().
Syntax:
datetime.now(ZoneInfo('timezone name'))Code language: Python (python)
Tip: UTC is the common time standard across the world. Store and calculate times in UTC, and convert them to a local timezone only when you display them to a user.
In this example, we get the time in four US timezones and several other cities. We start from one fixed UTC time and convert it, so the output is predictable. Replace now_utc with datetime.now(timezone.utc) to see the current time:
Output:
US Eastern 2026-07-08 09:37:34 EDT -0400 US Central 2026-07-08 08:37:34 CDT -0500 US Mountain 2026-07-08 07:37:34 MDT -0600 US Pacific 2026-07-08 06:37:34 PDT -0700 UK 2026-07-08 14:37:34 BST +0100 Germany 2026-07-08 15:37:34 CEST +0200 Japan 2026-07-08 22:37:34 JST +0900 Brazil 2026-07-08 10:37:34 -03 -0300 Australia 2026-07-08 23:37:34 AEST +1000
Notice -03 for Brazil: when a timezone has no common abbreviation, %Z shows the offset instead.
Get TimeZone Information Using tzinfo
An aware datetime can tell you about its timezone through three methods:
tzname(): returns the timezone abbreviation, for example'CDT'.utcoffset(): returns the total offset from UTC as a timedelta. It’s positive east of UTC and negative west of UTC, and it includes any DST adjustment.dst(): returns the DST adjustment as a timedelta, usually 1 hour when DST is in effect andtimedelta(0)otherwise. Soutcoffset() - dst()gives the standard offset of the place.
Example: Compare US Central time in summer and in winter.
Output:
2026-07-08 22:30 CDT TimeZone name: CDT UTC offset: -1 day, 19:00:00 DST: 1:00:00 Hours from UTC: -5.0 2026-01-08 22:30 CST TimeZone name: CST UTC offset: -1 day, 18:00:00 DST: 0:00:00 Hours from UTC: -6.0
A negative timedelta such as -5 hours is displayed as -1 day, 19:00:00 (minus one day plus 19 hours). Use total_seconds() / 3600 to get the offset in hours as a plain number.
Converting Between Timezones
Use the astimezone(tz) method to convert an aware datetime to another timezone. It returns a new datetime that represents the same moment, shown in the new timezone’s local time.
Output:
UTC DateTime: 2026-07-09 07:19:02 UTC +0000 US Central DateTime: 2026-07-09 02:19:02 CDT -0500 US Eastern DateTime: 2026-07-09 03:19:02 EDT -0400 India DateTime: 2026-07-09 12:49:02 IST +0530 Same moment? True
Calling astimezone() with no argument converts to your computer’s local timezone.
Note: If you call astimezone() on a naive datetime, Python assumes it’s in your computer’s local time. To avoid surprises, make the datetime aware first.
Working with Local Timezones
Your computer has a local timezone. Call astimezone() without an argument on any datetime to convert it to local time and find out the local timezone:
Output:
Local time: 2026-12-01 12:01:24.972714+05:30 Local timezone: IST 5:30:00 UTC 12:00 in local time: 2026-07-01 17:30:00+05:30
This example ran on a computer set to India Standard Time, so your output will show your own timezone.
Daylight Saving Time Pitfalls
Daylight saving time causes two surprises that are worth knowing about.
1. Adding a timedelta works on the wall clock. In 2026, US clocks move forward one hour at 2:00 AM on 8 March. Adding 24 hours to a time in a ZoneInfo timezone keeps the same clock time on the next day, but only 23 real hours have passed. To add exact elapsed time, do the arithmetic in UTC:
Output:
2026-03-08 12:00:00-04:00 2026-03-08 13:00:00-04:00
2. Some local times happen twice. When clocks move back in autumn, the hour from 1:00 to 2:00 AM repeats. Python uses the fold attribute to pick one: fold=0 (the default) is the first occurrence, and fold=1 is the second:
Output:
2026-11-01 01:30:00-04:00 EDT 2026-11-01 01:30:00-05:00 EST
Compare and Subtract Aware and Naive Datetimes
You can compare or subtract two aware datetimes even if they’re in different timezones. Python converts them to UTC first. But you can’t mix an aware datetime with a naive one:
Output:
Difference: 1:00:00 TypeError: can't subtract offset-naive and offset-aware datetimes
6 PM in Tokyo is 09:00 UTC and 9 AM in London is 08:00 UTC (London is UTC+1 in summer), so the Tokyo time is 1 hour later. To fix the error, make the naive datetime aware with replace(tzinfo=...) before the calculation.
Using the pytz Library
Before Python 3.9, the third-party pytz library (pip install pytz) was the usual way to work with timezones, so you’ll find it in many existing projects. Its main functions are:
pytz.utc: the UTC timezone.pytz.timezone('region'): creates the timezone object of a region.tz.localize(naive_dt): attaches a pytz timezone to a naive datetime.tz.normalize(dt): fixes the offset after arithmetic across a DST change.
Important: With pytz, never use replace(tzinfo=pytz.timezone(...)) or pass a pytz timezone to the datetime() constructor. pytz then uses the city’s historical “Local Mean Time” offset, which is several minutes off (for example -05:51 for Chicago instead of -05:00). Always use localize(). zoneinfo doesn’t have this problem, which is one reason it’s now preferred.
Summary
| Task | Use |
|---|---|
| Current time in a timezone | datetime.now(ZoneInfo('Asia/Tokyo')) |
| Current UTC time | datetime.now(timezone.utc) |
| Attach a timezone to a naive datetime | dt.replace(tzinfo=ZoneInfo(...)) |
| Convert to another timezone | dt.astimezone(ZoneInfo(...)) |
| Convert to local time | dt.astimezone() |
| Fixed UTC offset | timezone(timedelta(hours=9)) |
| Timezone name / offset / DST | dt.tzname(), dt.utcoffset(), dt.dst() |
