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
🌐
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 ...
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
Because naive datetime objects are treated by many datetime methods as local times, it is preferred to use aware datetimes to represent times in UTC. As such, the recommended way to create an object representing the current time in UTC is by calling datetime.now(timezone.utc).
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
🌐
Python
docs.python.org › 3 › library › zoneinfo.html
zoneinfo — IANA time zone support
When initializing TZPATH (either at import time or whenever reset_tzpath() is called with no arguments), the zoneinfo module will use the environment variable PYTHONTZPATH, if it exists, to set the search path. ... This is an os.pathsep-separated string containing the time zone search path to use.
🌐
InfluxData
influxdata.com › home › what are python timezones? a complete introduction | influxdata
What Are Python Timezones? A Complete Introduction | InfluxData
January 12, 2024 - The string displaying the date and time in the ISO-8601 format now contains the offset from UTC appended to it (the “-07:00”). Also, the tzinfo attribute on the object now correctly returns the name of the timezone.
🌐
Cheat Sheets
cheat.readthedocs.io › en › latest › python › timezones.html
Timezones in Python — Dan's Cheat Sheets 1 documentation
Now, we need to figure out what that timezone string means. Pick it out: ... We could have a timezone name or offset, but let’s assume the offset for now. 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. To create an aware object, Python wants a tzinfo object that has more information about the timezone than just the offset from UTC at this particular moment.
🌐
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 - Create datetime in a different timezone using pytz and timezone. Get timezone name, UTC offset, and DST offset. Timezone conversion
Find elsewhere
🌐
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.
🌐
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 objects, so we demonstrate their use next.
🌐
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.
🌐
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.
🌐
Maketimestamp
maketimestamp.com › tutorials › working-with-timezones-python
Maketimestamp
1from datetime import datetime 2from zoneinfo import ZoneInfo 3 4def convert_timezone(dt, from_tz, to_tz): 5 """ 6 Convert datetime between timezones 7 8 Args: 9 dt: datetime object (naive or aware) 10 from_tz: Source timezone string (e.g., 'America/New_York') 11 to_tz: Target timezone string (e.g., 'Asia/Tokyo') 12 13 Returns: 14 Timezone-aware datetime in target timezone 15 """ 16 # If datetime is naive, localize it first 17 if dt.tzinfo is None: 18 dt = dt.replace(tzinfo=ZoneInfo(from_tz)) 19 20 # Convert to target timezone 21 return dt.astimezone(ZoneInfo(to_tz)) 22 23# Usage 24naive_dt =
🌐
PYnative
pynative.com › home › python › python datetime › list all timezones in python
List All TimeZones in Python – PYnative
December 5, 2021 - Use Python Pytz and zoneinfo to get the List of All Timezones. Also, Get Timezones of an Any Country
🌐
Python
docs.python.org › 3 › library › time.html
time — Time access and conversions
The offset of the local (non-DST) ... note below. ... A tuple of two strings: the first is the name of the local non-DST timezone, the second is the name of the local DST timezone....
🌐
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 objects, so we demonstrate their use next.
🌐
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 objects, so we demonstrate their use next.