I am trying to convert this tring into a datetime object so I can remove the timezone. I am using the strptime function to turn it into a datetime object
createdAt = datetime.strptime(createdAt, 'YYYY-MM-DDThh:mm:ss.sssZ')
. However, even though this looks correct I still get the error: ValueError: time data '2020-11-26T18:53:09.284Z' does not match format 'YYYY-MM-DDThh:mm:ss.sssZ'
. After I do this I plan to use the code createdAt = createdAt.replace(tzinfo=None)
to replace the timezone info. Can someone tell me how my format is incorrect?
Asked
Active
Viewed 28 times
0

Jonathan
- 441
- 1
- 9
- 28
-
2`datetime.strptime(createdAt, '%Y-%m-%dT%H:%M:%S.%fZ')` works for me. – Chris Charley Nov 26 '20 at 19:11
-
1Apparently, that's not the correct formatting for `strptime`. See [some docs](https://www.programiz.com/python-programming/datetime/strptime) or this [related Q&A](https://stackoverflow.com/questions/127803/how-do-i-parse-an-iso-8601-formatted-date) – Pac0 Nov 26 '20 at 19:12
-
@ChrisCharley Thank you – Jonathan Nov 26 '20 at 19:17