0

I have the below setup to convert the dateTime string from a JSON to a DateTime variable in Python.

datetime_object = datetime.strptime(item.published.strip(), '&a, %d %b %Y %H:%M:%S %Z')

below is the error, where is my formatting going wrong?

ValueError: time data 'Wed, 21 Jul 2021 05:00:00 +0000' does not match format '&a, %d %b %Y %H:%M:%S %Z'

0

2 Answers 2

1

Two issues. First, you need %z at the end. %Z is a time zone name (like UTC). Second, you have a typo at the start - you need %a instead of &a:

datetime_object = datetime.strptime(item.published.strip(), '%a, %d %b %Y %H:%M:%S %z')
Sign up to request clarification or add additional context in comments.

Comments

0

You have some mistakes:

  1. %a instead of &a.
  2. %z instead of %Z

Code with correction:

datetime_object = datetime.datetime.strptime(dt.strip(), '%a, %d %b %Y %H:%M:%S %z')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.