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
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.to_datetime.html
pandas.to_datetime — pandas 3.0.1 documentation - PyData |
If Timestamp convertible (Timestamp, dt.datetime, np.datetimt64 or date string), origin is set to Timestamp identified by origin. If a float or integer, origin is the difference (in units determined by the unit argument) relative to 1970-01-01. ... If True, use a cache of unique, converted dates to apply the datetime conversion. May produce significant speed-up when parsing duplicate date strings, especially ones with timezone offsets.
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 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.
🌐
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)....
🌐
GeeksforGeeks
geeksforgeeks.org › convert-string-to-datetime-in-python-with-timezone
Convert string to datetime in Python with timezone - GeeksforGeeks
November 29, 2022 - string datetime: 2021-09-01 15:27:05.004573 +0530 datestring class is : <class 'str'> converted to datetime: 2021-09-01 15:27:05.004573+05:30 datetime_obj class is : <class 'datetime.datetime'> ... # Python3 code to demonstrate # Getting datetime object using a date_string # importing datetime module import datetime # datestring for which datetime_obj required date_string = '2021-09-01 15:27:05' # using strptime() to get datetime object datetime_obj = datetime.datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S') # Printing datetime print(datetime_obj)
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Timestamp.html
pandas.Timestamp — pandas 3.0.1 documentation
Python datetime.datetime object. ... There are essentially three calling conventions for the constructor. The primary form accepts four parameters. They can be passed by position or keyword. The other two forms mimic the parameters from datetime.datetime. They can be passed by either position or keyword, but not both mixed together. ... >>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific') Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')
🌐
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():
Find elsewhere
🌐
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 # ... ISO Date', x)Code language: Python (python) Run ... First, use the strptime() method to convert a string object to datetime. Next, use the timestamp() function to extract the timestamp ...
🌐
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 ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-to-datetime-strptime
How To Convert a String to a datetime Object in Python | DigitalOcean
December 13, 2024 - In this article, you’ll use strptime() to convert strings into datetime and struct_time() objects. Deploy your Python applications from GitHub using DigitalOcean App Platform.
🌐
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 - Python supports timezone-aware objects natively, but parsing the timezone from a string is the tricky part. Now let’s tackle the main approaches. datetime.strptime() is the strictest option: fast, deterministic, and ideal when your data format is fixed (logs, telemetry, structured API fields). It requires you to define an exact format string, including timezone parsing with %z. Here’s a complete example that parses a timestamp with microseconds and a numeric offset:
🌐
Flexiple
flexiple.com › python › python-unix-timestamp
Converting DateTime to UNIX Timestamp in Python - Flexiple
To ensure the time module or DateTime object is in UTC, the pytz library, which provides time zone support, can be utilised. First, create a DateTime object with the desired time and then set its timezone to UTC using pytz.
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-date-string-to-timestamp-in-python
Convert Date String to Timestamp in Python - GeeksforGeeks
October 29, 2025 - Explanation: s is date string, which is parsed into a datetime object dt using the format %d/%m/%Y. dt.timestamp() then converts it to a Unix timestamp, which is stored in res. calendar.timegm() method takes a UTC time tuple and returns an integer ...
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.to_datetime.html
pandas.to_datetime — pandas 3.0.1 documentation
If Timestamp convertible (Timestamp, dt.datetime, np.datetimt64 or date string), origin is set to Timestamp identified by origin. If a float or integer, origin is the difference (in units determined by the unit argument) relative to 1970-01-01. ... If True, use a cache of unique, converted dates to apply the datetime conversion. May produce significant speed-up when parsing duplicate date strings, especially ones with timezone offsets.
🌐
Databricks Community
community.databricks.com › t5 › data-engineering › how-to-convert-string-to-datetime-with-correct-timezone › td-p › 10741
How to convert string to datetime with correct timezone?
December 20, 2024 - Secondly, from what I can tell, using the TO_TIMESTAMP function will apply the timezone for your session (which might not be the timezone you want). I didn't realise this could be solved pretty easily by simply pasting your timezone to the end of the date string, like this;
🌐
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 above references and general use of the strptime method provides the groundwork for converting strings to datetime objects in Python. The essential steps of this process are as follows: ... Below is a slightly more complex example in which ...