I also get this error, so I made a little function to use whenever I deal with ISO times.
def ISOtstr(iso):
dcomponents = [1,1,1]
dcomponents[0] = iso[:4]
dcomponents[1] = iso[5:7]
dcomponents[2] = iso[8:10]
tcomponents = [1,1,1]
tcomponents[0] = iso[11:13]
tcomponents[1] = iso[14:16]
tcomponents[2] = iso[17:19]
d = dcomponents
t = tcomponents
string = "{}-{}-{} {}:{}:{}".format(d[0],d[1],d[2],t[0],t[1],t[2])
return string
Convert your ISO to a string:
string = '2019-06-18T11:00:10.499378622Z'
date_string = ISOtstring(string)
date_obj = datetime.datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S')
#Output
#datetime.datetime(2019, 6, 18, 11, 0, 10)
There is most likely a better way to do it. But I use this whenever dealing with ISO strings.
If your using it frequently you could make this a separate function:
def ISOtdatetime(iso):
date_string = ISOtstring(iso)
date_obj = datetime.datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S')
return date_obj
Just realized I had some meaningless code in there from when I first created the function. They have been removed.