How to remove timezone information from DateTime object in Python
Last Updated :
17 Jun, 2025
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)
OutputWith 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)
Output2025-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)
Output2025-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)
Output2025-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)
Output2025-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.
Similar Reads
How to make a timezone aware datetime object in Python A naive datetime in Python contains only the date and time, while a timezone-aware datetime includes timezone details, such as the UTC offset or timezone name, allowing it to accurately represent an exact moment in time. Creating a timezone-aware datetime means adding this timezone information to a
3 min read
How to convert Python's .isoformat() string back into datetime object In this article, we will learn how to convert Pythons .isoFormat() string back into a datetime object. Here we are using the current time and for that, we will store the current time in the current_time variable. The function now() of this module, does the job perfectly. Example: Getting current tim
1 min read
Remove Seconds from the Datetime in Python In Python, the datetime module provides classes for manipulating dates and times. Sometimes we may need to remove the seconds component from a datetime object, either for display purposes, to store in a database, or for formatting consistency. In this article we will explore different approaches to
2 min read
How to add time onto a DateTime object in Python In Python, adding time (such as hours, minutes, seconds, or days) to a datetime object is commonly done using the timedelta class from the datetime module. This allows precise manipulation of date and time values, including performing arithmetic operations on datetime objects. It's key features incl
3 min read
Working with Datetime Objects and Timezones in Python Python provides tools for managing date and time using the datetime module. Whether you're fetching the current time, formatting it, handling timezones or calculating time differences, this module makes it simple. For example, you can easily convert "2001-11-15 01:20:25" from Asia/Kolkata to America
4 min read