W3docs

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.

You can use the datetime.fromisoformat() method to parse an ISO 8601-formatted date in Python. Here is an example:

parse an ISO 8601-formatted date in Python using the datetime.fromisoformat method

from datetime import datetime

date_string = "2022-11-15T09:00:00"
date_object = datetime.fromisoformat(date_string)
print(date_object)

This will output:


2022-11-15 09:00:00

Note that this method is available on python 3.7+ If you are using python version less than 3.7, you can use dateutil library to parse ISO8601 date string.

parse an ISO 8601-formatted date in Python using the dateutil module

from dateutil import parser

date_string = "2022-11-15T09:00:00"
date_object = parser.parse(date_string)
print(date_object)

This will also output:


2022-11-15 09:00:00