0

I am trying to convert the string below into a datetime object using datetime.strptime, and I just can't seem to figure out .746Z at the end.

datetime_str = '2022-04-21T08:17:49.746Z'

datetime_object = datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S.%z')
print(datetime_object)
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Clay Campbell
  • 168
  • 13
  • 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 Dec 07 '22 at 05:52
  • Hi - I think your reference is a more complete answer to avoiding having to use strptime(). But they would have to dig through it to get to this specific questions about using strptime(). If not, I can delete! Thanks! – Clay Campbell Dec 07 '22 at 06:13
  • strptime is fine, actually you're just missing the %f for the fractional seconds. I just wanted to link the other question which is a bit more general. You might not want to delete your question, since other people might stumble across your specific problem ;-) – FObersteiner Dec 07 '22 at 06:35

0 Answers0