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. Here is an example:

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

Watch a course Python - The Practical Guide

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.

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