Open In App

How to remove timezone information from DateTime object in Python

Last Updated : 17 Jun, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

In Python, the tzinfo attribute of a datetime object indicates the timezone information. If tzinfo is None, the object is naive i.e., has no timezone. Otherwise, it's aware. Example:

Python
from datetime import datetime, timezone

dt_aware = datetime.now(timezone.utc)
print("With tzinfo:", dt_aware)
print("tzinfo attribute:", dt_aware.tzinfo)

Output
With tzinfo: 2025-06-16 04:38:51.880480+00:00
tzinfo attribute: UTC

Explanation: We create a timezone-aware datetime using datetime.now(timezone.utc), which returns the current UTC time with a +00:00 offset and tzinfo attribute confirms it's set to UTC.

While timezone-aware datetimes are useful for global time calculations and API integrations, there are situations such as local logging, database storage or display formatting where you may want to strip the timezone information and work with naive datetime objects. Let’s now explore the different methods to do this efficiently.

Using datetime.replace(tzinfo=None)

This is the efficient way to remove timezone information. It doesn't change the actual time it just removes the timezone tag (tzinfo) from the datetime object, making it naive.

Python
from datetime import datetime, timezone

dt = datetime.now(timezone.utc)
res = dt.replace(tzinfo=None)
print(res)

Output
2025-06-16 04:31:15.453160

Explanation: We create a UTC-aware datetime, then use .replace(tzinfo=None) to remove the timezone information, making the datetime naive.

Using datetime.astimezone(None)

This method first converts the datetime to local time using astimezone(None) and then removes the timezone info. It's useful if your original datetime is in UTC and you want to both convert to local time and strip tzinfo.

Python
from datetime import datetime, timezone

dt = datetime.now(timezone.utc)
res = dt.astimezone(None).replace(tzinfo=None)
print(res)

Output
2025-06-16 04:32:21.461428

Explanation: astimezone(None) converts the time to your local timezone. .replace(tzinfo=None) then removes the timezone information, giving you a naive datetime in local time.

Using strftime() + strptime()

This method converts the datetime to a string and then parses it back as a naive datetime object. It’s not the most efficient but can be helpful when you're already working with formatted date strings.

Python
from datetime import datetime, timezone

dt = datetime.now(timezone.utc)
dt_str = dt.strftime("%Y-%m-%d %H:%M:%S.%f")
res = datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S.%f")
print(res)

Output
2025-06-16 04:34:00.058231

Explanation: strftime() turns the aware datetime into a formatted string excluding timezone and strptime() re-parses it into a new, naive datetime object.

Using pytz

If you're using the pytz library, you can localize your naive datetime to a specific timezone, then strip the timezone info using replace(tzinfo=None). This is useful in legacy code or when you need timezone support beyond the standard library.

Python
from datetime import datetime
import pytz

tz = pytz.timezone("Asia/Kolkata")
dt = tz.localize(datetime.now())
res = dt.replace(tzinfo=None)
print(res)

Output
2025-06-16 04:53:30.365962

Explanation: We localize a naive datetime to the Asia/Kolkata timezone using pytz. Then, we use .replace(tzinfo=None) to remove the timezone info from the localized object.


Next Article
Article Tags :
Practice Tags :

Similar Reads