I've been trying to convert a timestamp that is a string to a datetime object. The problem is the timestamps formatting. I haven't been able to properly parse the timestamp using datetime.datetime.strptime
. I could write my own little parser as its a simple problem but I was hoping to use strptime
function, I just need help on the formatting.
Example
import datetime
formater = "%y-%m-%dT%H:%M:%SZ"
str_timestamp = "2021-03-13T18:27:37.60918Z"
timestamp = datetime.datetime.strptime(str_timestamp, formater)
print (timestamp)
Output
builtins.ValueError: time data '2021-03-13T18:27:37.60918Z' does not match format '%y-%m-%dT%H:%M:%SZ'
I'm clearly not symbolizing the formatter properly, the T
and Z
parts are what I can't account for.