0

I need convert a set of strings that is in this format "2020-01-01 00:00:00+01:00".

I try use this:

from datetime import datetime

date = datetime.strptime("2020-01-01 00:00:00+01:00", '%Y-%m-%d %H:%M:%S+%Z')

But i have this output:

>> ValueError: time data '2020-01-01 00:00:00+01:00' does not match format '%Y-%m-%d %H:%M:%S+%Z'

How can i convert this date?

  • The format is pretty much ISO8601, so you can use `datetime.fromisoformat` – FObersteiner Mar 16 '21 at 06:31
  • Does this answer your question? [How do I parse an ISO 8601-formatted date?](https://stackoverflow.com/questions/127803/how-do-i-parse-an-iso-8601-formatted-date) – FObersteiner Mar 16 '21 at 08:22

1 Answers1

1

You dont need to include the + of the timezone, and it's a lowercase z

from datetime import datetime

date = datetime.strptime("2020-01-01 00:00:00+01:00", '%Y-%m-%d %H:%M:%S%z')

print(date)
camionegra
  • 46
  • 5