I prefer using the dateutil library for timezone handling and generally solid date parsing. If you were to get an ISO 8601 string like: 2010-05-08T23:41:54.000Z you'd have a fun time parsing that with strptime, especially if you didn't know up front whether or not the timezone was included. pyiso8601 has a couple of issues (check their tracker) that I ran into during my usage and it hasn't been updated in a few years. dateutil, by contrast, has been active and worked for me:

from dateutil import parser
yourdate = parser.parse(datestring)
🌐
Readthedocs
pyiso8601.readthedocs.io
pyiso8601: ISO 8601 Parsing for Python — pyiso8601 0.1.10 documentation
This module parses the most common forms of ISO 8601 date strings (e.g. 2007-01-14T20:34:22+00:00) into datetime objects. >>> import iso8601 >>> iso8601.parse_date("2007-01-25T12:00:00Z") datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.Utc>) >>> See the LICENSE file for the license this ...
Discussions

How to parse ISO 8601 date in Python? - TestMu AI Community
How can I parse an ISO 8601-formatted date and time in Python date-time from isoformat? I need to parse RFC 3339 strings like “2008-09-03T20:56:35.450686Z” into Python’s datetime type. I have found strptime in the Python standard library, but it is not very convenient. More on community.testmuai.com
🌐 community.testmuai.com
0
December 18, 2024
python - How do I parse an ISO 8601-formatted date and time? - Stack Overflow
I need to parse RFC 3339 strings like "2008-09-03T20:56:35.450686Z" into Python's datetime type. I have found strptime in the Python standard library, but it is not very convenient. How d... More on stackoverflow.com
🌐 stackoverflow.com
Convert Date String in Filenames to ISO Date Format
As far as I know there is not a way to do automatic month to number translation. So you will need 12 separate expression and replace with the right number. Example: Jul_(\d\d)_(\d{4}) Replace: \207\1 Repeat for the other months. RegEx 101 demo I’m sure this could be done more cleanly with are more powerful scripting language, like powerShell. But that is not my strong suit. More on reddit.com
🌐 r/regex
7
2
January 23, 2021
What will be the golang equivalent of the ISO UTC timestamp in python `datetime.datetime.utcnow().isoformat()` ?
ISO-8601 (Python) and RFC3339 (Golang) I believe refer to the same thing. Try this: package main import ( "time" "fmt" ) func main() { fmt.Println(time.Now().UTC().Format(time.RFC3339)) } EDIT: At the time of my posting, OP hadn’t included a sample of what they wanted, with miliseconds. More on reddit.com
🌐 r/golang
2
2
July 17, 2019
People also ask

Q3. Why does the method strptime() fail on some ISO 8601 strings?
It fails because it requires an exact format string and does not support timezone parsing out of the box.
🌐
intellipaat.com
intellipaat.com › home › blog › how to parse iso 8601-formatted date and time in python
How to Parse ISO 8601-Formatted Date and Time in Python
Q5. Can I convert an ISO 8601 string directly into UTC?
Yes, when you parse the ISO 8601 string into a datetime object, you should be able to convert it to UTC using the .astimezone(timezone.utc) method.
🌐
intellipaat.com
intellipaat.com › home › blog › how to parse iso 8601-formatted date and time in python
How to Parse ISO 8601-Formatted Date and Time in Python
Q1. What does the Z mean in ISO 8601?
In this instance, Z indicates that the time is in UTC (Zulu Time), which is equivalent to a timezone offset of +00:00.
🌐
intellipaat.com
intellipaat.com › home › blog › how to parse iso 8601-formatted date and time in python
How to Parse ISO 8601-Formatted Date and Time in Python
🌐
Reddit
reddit.com › r/python › psa: as of python 3.11, `datetime.fromisoformat` supports most iso 8601 formats (notably the "z" suffix)
r/Python on Reddit: PSA: As of Python 3.11, `datetime.fromisoformat` supports most ISO 8601 formats (notably the "Z" suffix)
August 28, 2023 -

In Python 3.10 and earlier, datetime.fromisoformat only supported formats outputted by datetime.isoformat. This meant that many valid ISO 8601 strings could not be parsed, including the very common "Z" suffix (e.g. 2000-01-01T00:00:00Z).

I discovered today that 3.11 supports most ISO 8601 formats. I'm thrilled: I'll no longer have to use a third-party library to ingest ISO 8601 and RFC 3339 datetimes. This was one of my biggest gripes with Python's stdlib.

It's not 100% standards compliant, but I think the exceptions are pretty reasonable:

  • Time zone offsets may have fractional seconds.

  • The T separator may be replaced by any single unicode character.

  • Ordinal dates are not currently supported.

  • Fractional hours and minutes are not supported.

https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat

🌐
LabEx
labex.io › tutorials › python-how-to-create-datetime-objects-from-iso-8601-date-strings-417942
How to create datetime objects from ISO-8601 date strings | LabEx
In this example, we first import the datetime module from the Python standard library. We then define an ISO-8601 date string and use the datetime.fromisoformat() function to parse it and create a datetime object.
🌐
GitHub
github.com › closeio › ciso8601
GitHub - closeio/ciso8601: Fast ISO8601 date time parser for Python written in C · GitHub
ciso8601 converts ISO 8601 or RFC 3339 date time strings into Python datetime objects. Since it's written as a C module, it is much faster than other Python libraries. Tested with cPython 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14.
Starred by 575 users
Forked by 49 users
Languages   Python 63.7% | C 34.1% | Dockerfile 1.6% | Shell 0.6%
🌐
PYnative
pynative.com › home › python › python datetime › python iso 8601 datetime
Python Get ISO 8601 Datetime [4 Ways] – PYnative
May 27, 2022 - Get current ISO 8601 datetime in Python. Also, convert the datetime to ISO 8601 format. Learn how to convert datetime with timezone information to ISO 8601 format. Also, learn how to convert UTC to ISO 8601 format.
Find elsewhere
🌐
TestMu AI Community
community.testmuai.com › ask a question
How to parse ISO 8601 date in Python? - TestMu AI Community
December 18, 2024 - How can I parse an ISO 8601-formatted date and time in Python date-time from isoformat? I need to parse RFC 3339 strings like “2008-09-03T20:56:35.450686Z” into Python’s datetime type. I have found strptime in the Pytho…
🌐
Note.nkmk.me
note.nkmk.me › home › python
Convert Between Isoformat String and datetime in Python | note.nkmk.me
August 22, 2023 - In Python, you can handle date and time information with the datetime module from the standard library. The datetime module provides methods, such as isoformat() and fromisoformat(), for converting between ISO format (ISO 8601) strings and datetime ...
Top answer
1 of 16
700

isoparse function from python-dateutil

The python-dateutil package has dateutil.parser.isoparse to parse not only RFC 3339 datetime strings like the one in the question, but also other ISO 8601 date and time strings that don't comply with RFC 3339 (such as ones with no UTC offset, or ones that represent only a date).

>>> import dateutil.parser
>>> dateutil.parser.isoparse('2008-09-03T20:56:35.450686Z') # RFC 3339 format
datetime.datetime(2008, 9, 3, 20, 56, 35, 450686, tzinfo=tzutc())
>>> dateutil.parser.isoparse('2008-09-03T20:56:35.450686') # ISO 8601 extended format
datetime.datetime(2008, 9, 3, 20, 56, 35, 450686)
>>> dateutil.parser.isoparse('20080903T205635.450686') # ISO 8601 basic format
datetime.datetime(2008, 9, 3, 20, 56, 35, 450686)
>>> dateutil.parser.isoparse('20080903') # ISO 8601 basic format, date only
datetime.datetime(2008, 9, 3, 0, 0)

The python-dateutil package also has dateutil.parser.parse. Compared with isoparse, it is presumably less strict, but both of them are quite forgiving and will attempt to interpret the string that you pass in. If you want to eliminate the possibility of any misreads, you need to use something stricter than either of these functions.

Comparison with Python 3.7+’s built-in datetime.datetime.fromisoformat

dateutil.parser.isoparse is a full ISO-8601 format parser, but in Python ≤ 3.10 fromisoformat is deliberately not. In Python 3.11, fromisoformat supports almost all strings in valid ISO 8601. See fromisoformat's docs for this cautionary caveat. (See this answer).

2 of 16
504

Since Python 3.11, the standard library’s datetime.datetime.fromisoformat supports most valid ISO 8601 input (and some non-valid input, see docs). In earlier versions it only parses a specific subset, see the cautionary note at the end of the docs. If you are using Python 3.10 or earlier on strings that don't fall into that subset (like in the question), see other answers for functions from outside the standard library.

The current docs (so exceptions listed are still valid for Python 3.13):

classmethod datetime.fromisoformat(date_string):

Return a datetime corresponding to a date_string in any valid ISO 8601 format, with the following exceptions:

  1. Time zone offsets may have fractional seconds.
  2. The T separator may be replaced by any single unicode character.
  3. Fractional hours and minutes are not supported.
  4. Reduced precision dates are not currently supported (YYYY-MM, YYYY).
  5. Extended date representations are not currently supported (±YYYYYY-MM-DD).
  6. Ordinal dates are not currently supported (YYYY-OOO).

Examples:

>>> from datetime import datetime
>>> datetime.fromisoformat('2011-11-04')
datetime.datetime(2011, 11, 4, 0, 0)
>>> datetime.fromisoformat('20111104')
datetime.datetime(2011, 11, 4, 0, 0)
>>> datetime.fromisoformat('2011-11-04T00:05:23')
datetime.datetime(2011, 11, 4, 0, 5, 23)
>>> datetime.fromisoformat('2011-11-04T00:05:23Z')
datetime.datetime(2011, 11, 4, 0, 5, 23, tzinfo=datetime.timezone.utc)
>>> datetime.fromisoformat('20111104T000523')
datetime.datetime(2011, 11, 4, 0, 5, 23)
>>> datetime.fromisoformat('2011-W01-2T00:05:23.283')
datetime.datetime(2011, 1, 4, 0, 5, 23, 283000)
>>> datetime.fromisoformat('2011-11-04 00:05:23.283')
datetime.datetime(2011, 11, 4, 0, 5, 23, 283000)
>>> datetime.fromisoformat('2011-11-04 00:05:23.283+00:00')
datetime.datetime(2011, 11, 4, 0, 5, 23, 283000, tzinfo=datetime.timezone.utc)
>>> datetime.fromisoformat('2011-11-04T00:05:23+04:00')   
datetime.datetime(2011, 11, 4, 0, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=14400)))

New in version 3.7.

Changed in version 3.11: Previously, this method only supported formats that could be emitted by date.isoformat() or datetime.isoformat().

If you only need dates, and not datetimes, you can use datetime.date.fromisoformat:

>>> from datetime import date
>>> date.fromisoformat("2024-01-31")
datetime.date(2024, 1, 31)
🌐
W3docs
w3docs.com › python
How do I parse an ISO 8601-formatted date?
You can use the datetime.fromisoformat() method to parse an ISO 8601-formatted date in Python.
🌐
IncludeHelp
includehelp.com › python › how-do-i-parse-an-iso-8601-formatted-date.aspx
How do I parse an ISO 8601-formatted date in Python?
May 3, 2020 - Python provides a datetime standard library which introduces datetime.isoformat(). As per the python docs. ... It represents the date as a String in ISO 8601 format, 'YYYY-MM-DD'.
🌐
Learn By Example
learnbyexample.org › working-with-iso-8601-in-python
Working with ISO 8601 in Python - Learn By Example
April 23, 2024 - To parse an ISO 8601 formatted string back into a Python datetime object, use the fromisoformat() method.
🌐
pytz
pythonhosted.org › dt8601 › tutorial.html
Using the ISO8601 parser — dt8601 0.2.0 documentation
One of the advantages of using this package is that you do not have to specify the format of the date/time string, the parser will automatically detect the format used. ISO8601 specifies the list of valid date and time formats, so there is no need to provide redundant information.
🌐
sqlpey
sqlpey.com › python › top-12-methods-to-parse-iso-8601-dates-in-python
Top 12 Methods to Parse ISO 8601 Dates in Python - sqlpey
December 5, 2024 - Since Python 3.11, the standard library’s datetime.datetime.fromisoformat function supports virtually all valid ISO 8601 formats: from datetime import datetime ## Example ISO 8601 date string iso_date = "2008-09-03T20:56:35.450686Z" ## Parsing the date parsed_date = datetime.fromisoformat(iso_date.replace('Z', '+00:00')) print(parsed_date) # Output: 2008-09-03 20:56:35.450686+00:00
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
Return a date corresponding to a date_string given in any valid ISO 8601 format, with the following exceptions:
🌐
PyPI
pypi.org › project › iso8601
iso8601
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Ham1
blog.ham1.co.uk › 2023 › 05 › 29 › python-parse-iso-date-with-z-at-end
Parse ISO 8601 date ending in Z with Python - Graham Russell's Blog
May 29, 2023 - from datetime import datetime import pytz iso_date_string = "2023-05-29T10:30:00Z" parsed_date = datetime.fromisoformat(iso_date_string[:-1]) # Removing the 'Z' at the end utc_timezone = pytz.timezone('UTC') aware_date = parsed_date.replace(tzinfo=utc_timezone) print(aware_date)
🌐
TutorialsPoint
tutorialspoint.com › How-do-I-get-an-ISO-8601-date-in-string-format-in-Python
How do I get an ISO 8601 date in string format in Python?
June 16, 2025 - In the following program, we retrieve the current UTC datetime using the utcnow() method and convert it to a string in ISO 8601 format using the isoformat() method.
🌐
PyPI
pypi.org › project › isodate
isodate · PyPI
This module implements ISO 8601 date, time and duration parsing. The implementation follows ISO8601:2004 standard, and implements only date/time representations mentioned in the standard.
      » pip install isodate
    
Published   Oct 08, 2024
Version   0.7.2
🌐
Intellipaat
intellipaat.com › home › blog › how to parse iso 8601-formatted date and time in python
How to Parse ISO 8601-Formatted Date and Time in Python
October 29, 2025 - One of the simplest methods to work on is the datetime.fromisoformat() method, available from Python version 3.7 and onwards. This function parses date strings that strictly follow the ISO format, including those with or without time components.