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 UTC datetime string to local datetime in Python? - Python - Data Science Dojo Discussions
Hi, I have a string representing a datetime in UTC format, and I want to convert it to the local timezone. I’ve tried using datetime.strptime() and pytz but I’m not getting the expected results. Here’s my code: This code runs without errors, but the output is incorrect. More on discuss.datasciencedojo.com
🌐 discuss.datasciencedojo.com
1
0
May 8, 2023
Parse "Z" timezone suffix in datetime - Ideas - Discussions on Python.org
This is already opened as BPO 35829 but I wanted to ask about it over here for discussion. Problem Statement The function datetime.fromisoformat() parses a datetime in ISO-8601, format: >>> datetime.fromisoformat('2019-08-28T14:34:25.518993+00:00') datetime.datetime(2019, 8, 28, 14, 34, 25, ... More on discuss.python.org
🌐 discuss.python.org
10
August 28, 2019
🌐
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():
🌐
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 ...
🌐
Python Morsels
pythonmorsels.com › converting-a-string-to-a-datetime
Converting a string to a datetime - Python Morsels
September 30, 2024 - Copied to clipboard. Tags ... You need the strptime class method. That's the easy part. The hard part is figuring out which format string you need to specify to parse your date string properly.
🌐
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 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
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › How-to-convert-date-and-time-with-different-timezones-in-Python
How to convert date and time with different timezones in Python?
August 25, 2023 - # importing datetime from datetime import datetime # importing pytz module import pytz # giving the format of datetime format = "%Y-%m-%d %H:%M:%S %Z%z" # getting the standard UTC time original_tz = pytz.timezone('Asia/Kolkata') # giving the timezone to which it is to be converted converted_tz = pytz.timezone('US/Eastern') # Getting the current time in the Asia/Kolkata Time Zone datetime_object = datetime.now(original_tz) # Format the above datetime using the strftime() print("Original Date & Time: in Asia/Kolkata ",datetime_object.strftime(format)) # Getting the current time in the US/Eastern
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-date-and-time-with-different-timezones-in-python
How to convert date and time with different timezones in Python? - GeeksforGeeks
April 22, 2021 - from datetime import datetime import pytz # get the standard UTC time original = pytz.utc # create datetime object dateTimeObj = datetime.now(original) print("Original Date & Time: ", dateTimeObj.strftime('%Y:%m:%d %H:%M:%S %Z %z')) # it will ...
🌐
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) ...
🌐
Analytics Vidhya
analyticsvidhya.com › home › convert string to datetime and vice-versa in python
Convert String to DateTime and Vice-Versa in Python - Analytics Vidhya
February 6, 2024 - If you’re working with pandas, the to_datetime() method can convert a string to a DateTime object. It provides additional functionalities, such as handling missing values and timezones.
🌐
iO Flood
ioflood.com › blog › python-datetime-to-string
Learn Python: Convert datetime to string (With Examples)
February 7, 2024 - Finally, we use the strftime() function to convert the datetime object into a string. As you start to delve deeper into Python’s datetime conversions, you’ll find that there are numerous date and time formats to consider.
🌐
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 - I have a field stored as a string in the format "12/30/2022 10:30:00 AM" If I use the function TO_DATE, I only get the date part... I want the full date and time. If I use the function TO_TIMESTAMP, I get the date and time, but it's assumed to be UTC, which isn't correct (it's actually the local t...
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
How to convert UTC datetime string to local datetime in Python? - Python - Data Science Dojo Discussions
May 8, 2023 - Hi, I have a string representing a datetime in UTC format, and I want to convert it to the local timezone. I’ve tried using datetime.strptime() and pytz but I’m not getting the expected results. Here’s my code: This c…
🌐
GeeksforGeeks
geeksforgeeks.org › converting-string-yyyy-mm-dd-into-datetime-in-python
Converting string into DateTime in Python - GeeksforGeeks
May 1, 2025 - The goal is to convert a date string like "2021/05/25" into a Python-recognized DateTime object such as 2021-05-25 00:00:00. This enables accurate and consistent date operations like comparisons, calculations and formatting when working with time-related data from sources like files or user input.
🌐
Python.org
discuss.python.org › ideas
Parse "Z" timezone suffix in datetime - Ideas - Discussions on Python.org
August 28, 2019 - This is already opened as BPO 35829 but I wanted to ask about it over here for discussion. Problem Statement The function datetime.fromisoformat() parses a datetime in ISO-8601, format: >>> datetime.fromisoformat('2019-08-28T14:34:25.518993+00:00') datetime.datetime(2019, 8, 28, 14, 34, 25, 518993, tzinfo=datetime.timezone.utc) The timezone offset in my example is +00:00, i.e. UTC.