As of Python 3.7, datetime.datetime.fromisoformat() can handle your format:

>>> import datetime
>>> datetime.datetime.fromisoformat('2012-11-01T04:16:13-04:00')
datetime.datetime(2012, 11, 1, 4, 16, 13, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000)))

In older Python versions you can't, not without a whole lot of painstaking manual timezone defining.

Python versions before version 3.9 do not include a timezone database, because it would be outdated too quickly. Instead, for those versions Python relied on external libraries, which can have a far faster release cycle, to provide properly configured timezones for you.

As a side-effect, this means that timezone parsing also needs to be an external library. If dateutil is too heavy-weight for you, use iso8601 instead, it'll parse your specific format just fine:

>>> import iso8601
>>> iso8601.parse_date('2012-11-01T04:16:13-04:00')
datetime.datetime(2012, 11, 1, 4, 16, 13, tzinfo=<FixedOffset '-04:00'>)

iso8601 is a whopping 4KB small. Compare that tot python-dateutil's 148KB.

As of Python 3.2 Python can handle simple offset-based timezones, and %z will parse -hhmm and +hhmm timezone offsets in a timestamp. That means that for a ISO 8601 timestamp you'd have to remove the : in the timezone:

>>> from datetime import datetime
>>> iso_ts = '2012-11-01T04:16:13-04:00'
>>> datetime.strptime(''.join(iso_ts.rsplit(':', 1)), '%Y-%m-%dT%H:%M:%S%z')
datetime.datetime(2012, 11, 1, 4, 16, 13, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000)))

The lack of proper ISO 8601 parsing was being tracked in Python issue 15873 (since migrated to GitHub issue #60077).

Answer from Martijn Pieters on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
In the following tzinfo_examples.py file there are some examples of tzinfo classes: import datetime as dt # A class capturing the platform's idea of local time. # (May result in wrong values on historical times in # timezones where UTC offset and/or the DST rules had # changed in the past.) import time ZERO = dt.timedelta(0) HOUR = dt.timedelta(hours=1) SECOND = dt.timedelta(seconds=1) STDOFFSET = dt.timedelta(seconds=-time.timezone) if time.daylight: DSTOFFSET = dt.timedelta(seconds=-time.altzone) else: DSTOFFSET = STDOFFSET DSTDIFF = DSTOFFSET - STDOFFSET class LocalTimezone(dt.tzinfo): def
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-string-to-datetime-in-python-with-timezone
Convert string to datetime in Python with timezone - GeeksforGeeks
July 23, 2025 - Converting a string to a datetime in Python with timezone means parsing a date-time string and creating a timezone-aware datetime object. For example, a string like '2021-09-01 15:27:05.004573 +0530' can be converted to a Python datetime object ...
Discussions

django - convert python datetime with timezone to string - Stack Overflow
Can you give an example about how the time tuples are constructed and what error you got? ... I am getting exactly this from the query datetime.datetime(2010, 7, 1, 0, 0, tzinfo=) I am not sure how the tuples are created ... The way you seem to be doing it, would work fine for both timezone aware and naive datetime objects. If you want to also add the timezone to your string... More on stackoverflow.com
🌐 stackoverflow.com
Can't beat the Timezone Strings challenge in Python
Cissie Scurlock is having issues with: I feel like I'm close to getting this but with this code I get the error: 'to_timezone` didn't return the right, converted datetime.' I've trie... More on teamtreehouse.com
🌐 teamtreehouse.com
4
December 4, 2014
How to convert a string date and time to a datetime with Eastern timezone?
It sounds like you have run into a common issue. 'US/Eastern' time is not the same thing as 'Eastern Standard Time'. It's there for backwards compatibility reasons. The timezone you might be looking for is called "America/New_York" More on reddit.com
🌐 r/learnpython
6
1
October 23, 2020
correct way to use timestamp with timezone
Set your database to GMT/UTC time zone and store all dates in GMT/UTC as well. Then you can do the calculation/offset for the users timezone on the front-end. Or the user can set the timezone after the database connection is made for the session length needed. EDIT: a good read as well https://www.enterprisedb.com/postgres-tutorials/postgres-time-zone-explained More on reddit.com
🌐 r/PostgreSQL
15
6
November 4, 2020
Top answer
1 of 7
167

As of Python 3.7, datetime.datetime.fromisoformat() can handle your format:

>>> import datetime
>>> datetime.datetime.fromisoformat('2012-11-01T04:16:13-04:00')
datetime.datetime(2012, 11, 1, 4, 16, 13, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000)))

In older Python versions you can't, not without a whole lot of painstaking manual timezone defining.

Python versions before version 3.9 do not include a timezone database, because it would be outdated too quickly. Instead, for those versions Python relied on external libraries, which can have a far faster release cycle, to provide properly configured timezones for you.

As a side-effect, this means that timezone parsing also needs to be an external library. If dateutil is too heavy-weight for you, use iso8601 instead, it'll parse your specific format just fine:

>>> import iso8601
>>> iso8601.parse_date('2012-11-01T04:16:13-04:00')
datetime.datetime(2012, 11, 1, 4, 16, 13, tzinfo=<FixedOffset '-04:00'>)

iso8601 is a whopping 4KB small. Compare that tot python-dateutil's 148KB.

As of Python 3.2 Python can handle simple offset-based timezones, and %z will parse -hhmm and +hhmm timezone offsets in a timestamp. That means that for a ISO 8601 timestamp you'd have to remove the : in the timezone:

>>> from datetime import datetime
>>> iso_ts = '2012-11-01T04:16:13-04:00'
>>> datetime.strptime(''.join(iso_ts.rsplit(':', 1)), '%Y-%m-%dT%H:%M:%S%z')
datetime.datetime(2012, 11, 1, 4, 16, 13, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000)))

The lack of proper ISO 8601 parsing was being tracked in Python issue 15873 (since migrated to GitHub issue #60077).

2 of 7
75

Here is the Python Doc for datetime object using dateutil package..

from dateutil.parser import parse

get_date_obj = parse("2012-11-01T04:16:13-04:00")
print get_date_obj
🌐
InfluxData
influxdata.com › home › what are python timezones? a complete introduction | influxdata
What Are Python Timezones? A Complete Introduction | InfluxData
January 12, 2024 - a list of some important timezones, along with the strings that identify them on the tz (aka Olson) database · how to use Python timezones, in two different approaches · Now, let’s cover more ground by answering common Python timezone questions. As you could see from our examples, you get timezones by either using the pytz library or the newer zoneinfo module:
🌐
Cheat Sheets
cheat.readthedocs.io › en › latest › python › timezones.html
Timezones in Python — Dan's Cheat Sheets 1 documentation
RFC 2282 says this is in the format [+-]HHMM: >>> sign = 1 >>> if tzs.startswith("-"): ... sign = -1 ... tzs = tzs[1:] ... elif tzs.startswith("+"): ... tzs = tzs[1:] ... >>> tzs '0400' >>> sign -1 ... Unfortunately, we can’t just plug that offset into our datetime.
🌐
Python Guides
pythonguides.com › convert-a-string-to-datetime-in-python
Convert Python String to Datetime with Timezone
September 23, 2025 - ... from datetime import datetime, timezone # Example timestamp string timestamp_str = "2025-09-23 14:30:00" # Step 1: Convert string to naive datetime dt_naive = datetime.strptime(timestamp_str, "%Y-%m-%d %H:%M:%S") # Step 2: Attach UTC timezone dt_utc = dt_naive.replace(tzinfo=timezone.utc) ...
🌐
alpharithms
alpharithms.com › home › tutorials › converting between strings and datetime objects in python
Converting Between Strings and Datetime Objects in Python - αlphαrithms
June 17, 2022 - Finally, we use the strptime method to convert the now-aware date object into a final output string which reflects the timezone information via the %T%t format syntax. The result of this code is as follows: Initial Timezone: None Updated Timezone: UTC Converted Timezone: 2022-06-17T18:23:59 UTC+0000 · The datetime module in Python allows developers to easily convert between strings and datetime objects.
Find elsewhere
🌐
Medium
medium.com › @lawjimmy123 › learn-how-to-handle-timestamps-and-timezones-in-python-in-2-minutes-50d0d3e8fa3a
Learn how to handle timestamps and timezones in Python in 2 minutes | by Jimmy Law | Medium
January 16, 2022 - In these cases, pytz accepts handy timezone strings like “Europe/London” that would automatically switch between the two timezones so you don’t have to worry about it. Here is an example for London. That’s it! That’s everything you need to know to work with timestamps and timezones in Python...
🌐
PYnative
pynative.com › home › python › python datetime › working with timezones in python
Python TimeZone: A Guide To Work With Different Timezones – PYnative
December 5, 2021 - So, in Python, to work with the ... timezone · For example, CT(Central Time) in North and South America is either 5 or 6 hours behind and represented as UTC-5 or UTC-6 based on the Day Light Saving....
🌐
pytz
pythonhosted.org › pytz
pytz - World Timezone Definitions for Python — pytz 2014.10 documentation
If you are installing using setuptools, you don’t even need to download anything as the latest version will be downloaded for you from the Python package index: ... >>> from datetime import datetime, timedelta >>> from pytz import timezone >>> import pytz >>> utc = pytz.utc >>> utc.zone 'UTC' >>> eastern = timezone('US/Eastern') >>> eastern.zone 'US/Eastern' >>> amsterdam = timezone('Europe/Amsterdam') >>> fmt = '%Y-%m-%d %H:%M:%S %Z%z'
🌐
TutorialsPoint
tutorialspoint.com › handling-timezone-in-python
Handling timezone in Python
April 18, 2023 - Use the strftime() function of the datetime object. The format string '%Y-%m- %d%H:%M:%S%Z%z' gives the year, month, day, hour, minute, and second, as well as the timezone abbreviation and timezone offset. This article covers the core concepts and practices for handling timezones in Python.
🌐
Python
docs.python.org › 3 › library › zoneinfo.html
zoneinfo — IANA time zone support
ZoneInfo(key): When constructed with the primary constructor, a ZoneInfo object is serialized by key, and when deserialized, the deserializing process uses the primary and thus it is expected that these are the same object as other references to the same time zone. For example, if europe_berlin_pkl is a string containing a pickle constructed from ZoneInfo("Europe/Berlin"), one would expect the following behavior:
🌐
Read the Docs
pvlib-python.readthedocs.io › en › v0.7.0 › timetimezones.html
Time and time zones — pvlib-python 0.7.0+0.ge2a8f31.dirty documentation
Yet another way to specify a time zone with a fixed offset is by using the string formulation. In [30]: pd.Timestamp('2015-1-1 00:00+0200') Out[30]: Timestamp('2015-01-01 00:00:00+0200', tz='pytz.FixedOffset(120)') Sometimes it’s convenient to use native Python datetime.date and datetime.datetime ...
🌐
HackerEarth
hackerearth.com › practice › notes › sachin › working-with-datetime-module-and-timezones-in-python
Working with datetime module and timezones in Python - Sachin Gupta
import pytz # assuming now contains ... You are free to explore them if you want to. Just to give an example suppose you have a datetime in string as 5 P.M....
🌐
Read the Docs
pvlib-python.readthedocs.io › en › v0.3.0 › timetimezones.html
Time and time zones — pvlib-python 0.3.0 documentation
Yet another way to specify a time zone with a fixed offset is by using the string formulation. In [30]: pd.Timestamp('2015-1-1 00:00+0200') Out[30]: Timestamp('2015-01-01 00:00:00+0200', tz='pytz.FixedOffset(120)') Sometimes it’s convenient to use native Python datetime.date and datetime.datetime ...
🌐
Team Treehouse
teamtreehouse.com › community › cant-beat-the-timezone-strings-challenge-in-python
Can't beat the Timezone Strings challenge in Python (Example) | Treehouse Community
December 4, 2014 - I feel like I'm close to getting this but with this code I get the error: 'to_timezone` didn't return the right, converted datetime.' I've tried including a fmt = '%Y-%m-%d %H:%M:%S' as a variable while returning new_datetime.strf(fmt) and and ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › working-with-datetime-objects-and-timezones-in-python
Working with Datetime Objects and Timezones in Python - GeeksforGeeks
July 23, 2025 - To understand this, let's look at the syntax of strptime(): ... import datetime dt = datetime.datetime.strptime("Jan 1, 2013 12:30 PM", "%b %d, %Y %I:%M %p") print(dt) ... The DateTime objects that we have been working with till now are what ...
🌐
Read the Docs
pvlib-python.readthedocs.io › en › v0.4.2 › timetimezones.html
Time and time zones — pvlib-python 0.4.2+0.g04b7a82.dirty documentation
Yet another way to specify a time zone with a fixed offset is by using the string formulation. In [30]: pd.Timestamp('2015-1-1 00:00+0200') Out[30]: Timestamp('2015-01-01 00:00:00+0200', tz='pytz.FixedOffset(120)') Sometimes it’s convenient to use native Python datetime.date and datetime.datetime ...