convert a scraped datetime into time

Viewed 25

I have a time in the following form:

"2021-08-11T12:16:04+02:00"

which I want to convert into this form:

"2021-08-11 14:16:04"

I've tried using the strftime method but couldn't figure how to convert that +02:00

1 Answers

This is straight ISO 8601 format.

>>> import datetime
>>> x = "2021-08-11T12:16:04+02:00"
>>> datetime.datetime.fromisoformat(x)
datetime.datetime(2021, 8, 11, 12, 16, 4, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200)))
Related