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
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
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-string-to-datetime-in-python-with-timezone
Convert string to datetime in Python with timezone - GeeksforGeeks
July 23, 2025 - Explanation: arrow.get(s) parses the date-time string s into an Arrow datetime object with timezone support, without requiring an explicit format string, providing a clean and user-friendly API.
Discussions

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
django - convert python datetime with timezone to string - Stack Overflow
I have date time tuples in the format of datetime.datetime(2010, 7, 1, 0, 0, tzinfo= ) How can I convert that into a date time string such as 2008-11-10 17:53:59 I am really just gettin... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert date string with timezone to datetime in python - Stack Overflow
I need to compare two date string and for that, I need to convert the date string to datetime object. An example of a date string is "2015-08-23T03:36:30-05:00". I am assuming "-05:0... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Using strftime from Datetime with "+02:00" as UTC/timezone?
Maybe it's because I have +02:00, but I should have +0200? Yes, that's a problem and you'll have to remove that colon in order to use datetime.strptime. Or did I make another mistake? You also left the % off of the minute placeholder. Instead of this headache, you could instead install the dateutil package, which automagically parses common formats like this: >>> from dateutil.parser import parse >>> parse("2020-06-13T17:27:24.165+02:00") datetime.datetime(2020, 6, 13, 17, 27, 24, 165000, tzinfo=tzoffset(None, 7200)) More on reddit.com
๐ŸŒ r/learnpython
2
1
June 28, 2020
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ converting-strings-datetime-objects
Convert String to DateTime in Python: Complete Guide with Examples | DataCamp
June 8, 2018 - Yes, you can handle time zones by using the pytz library in combination with datetime. First, convert the string to a datetime object, and then attach a time zone using pytz.timezone():
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ converting-strings-to-datetime-in-python
Converting Strings to datetime in Python
June 21, 2023 - Then using the astimezone() method, we have converted this datetime to "Europe/London" timezone. Both datetimes will print different values, using UTC offset as a reference link between them: America/New_York: 2022-11-30 21:24:30.123400-05:00 Europe/London: 2022-12-01 02:24:30.123400+00:00 ...
๐ŸŒ
Python Guides
pythonguides.com โ€บ convert-a-string-to-datetime-in-python
Convert Python String to Datetime with Timezone
September 23, 2025 - Learn step-by-step how to convert Python string to datetime with timezone using datetime, pytz, and dateutil. Includes full code examples and practical tips.
๐ŸŒ
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 - The datetime module in Python allows developers to easily convert between strings and datetime objects. Special attention should be given to ensuring timezone information is encoded, replaced, and converted to a string format as intended.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ datetime.html
datetime โ€” Basic date and time types
Because naive datetime objects ... recommended way to create an object representing a specific timestamp in UTC is by calling datetime.fromtimestamp(timestamp, tz=timezone.utc)....
Find elsewhere
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.to_datetime.html
pandas.to_datetime โ€” pandas 3.0.1 documentation - PyData |
If True, the function always returns a timezone-aware UTC-localized Timestamp, Series or DatetimeIndex. To do this, timezone-naive inputs are localized as UTC, while timezone-aware inputs are converted to UTC.
๐ŸŒ
InfluxData
influxdata.com โ€บ home โ€บ how to convert string to datetime in python
How to Convert String to Datetime in Python | InfluxData
October 30, 2023 - As youโ€™ve seen, the datetime module in Python is the one you use to handle date and time concerns. It contains several classes, but these are the main ones: date: contains only date information, without time of day, and itโ€™s a naive object ยท time: contains only time information, without being bound to any specific day ยท datetime: a combination of date, time, and timezone (i.e., an aware type)
๐ŸŒ
Vultr
docs.vultr.com โ€บ python โ€บ examples โ€บ convert-string-to-datetime
Python Program to Convert String to Datetime | Vultr Docs
November 22, 2024 - Converting strings into datetime objects in Python is an essential task for many applications involving date manipulations. By using Python's datetime.strptime() method, you can handle various date string formats efficiently. Remember to consider ...
๐ŸŒ
Rip Tutorial
riptutorial.com โ€บ parsing a string into a timezone aware datetime object
Python Language Tutorial => Parsing a string into a timezone aware...
UTC offset in the form +HHMM or -HHMM (empty string if the object is naive). ... For other versions of Python, you can use an external library such as dateutil, which makes parsing a string with timezone into a datetime object is quick.
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ python datetime โ€บ python string to datetime using strptime()
Python String to DateTime using Strptime() [5 Ways] โ€“ PYnative
December 5, 2021 - from datetime import datetime # Date string with UTC Offset. date_str = "23/Feb/2021:09:15:26 +0200" # %z to convert UTC offset to date dt_obj1 = datetime.strptime(date_str, "%d/%b/%Y:%H:%M:%S %z") print("Date Object With UTC offset::", dt_obj1) ...
๐ŸŒ
TheLinuxCode
thelinuxcode.com โ€บ home โ€บ convert string to datetime in python with timezone: practical parsing patterns for 2026
Convert String to Datetime in Python with Timezone: Practical Parsing Patterns for 2026 โ€“ TheLinuxCode
January 27, 2026 - If the string includes a timezone offset or zone abbreviation, parse it into a timezone-aware datetime. If the string has no timezone, decide on a default and attach it intentionally. Convert to UTC at the boundary of your system, but keep original timezone if you need to show it back to users. Python supports timezone-aware objects natively, but parsing the timezone from a string is the tricky part.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ convert string to datetime python
Convert String to Datetime Python: Comprehensive Guide & Examples
November 13, 2024 - Convert string to datetime Python easily with this guide. Learn datetime conversion methods, formats, handling time zones, and working with timedelta through examples.
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ question โ€บ how-to-convert-string-to-time-change-timezone-back-to-string
How to Convert a String to Time, Change the Timezone, and Convert Back to String - CodingTechRoom
Convert to the desired timezone: Change the timezone of your localized `datetime` object using the `astimezone()` method. Convert back to string: Finally, format the updated `datetime` object back to a string using `strftime` for user-friendly display.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ pandas-docs โ€บ stable โ€บ reference โ€บ api โ€บ pandas.to_datetime.html
pandas.to_datetime โ€” pandas 3.0.1 documentation
If True, the function always returns a timezone-aware UTC-localized Timestamp, Series or DatetimeIndex. To do this, timezone-naive inputs are localized as UTC, while timezone-aware inputs are converted to UTC.