When calling an API, I am getting seven digits in the decimal part of the seconds in datetime string. Below is the value that I got in response:
"startDateTime": "2020-09-16T10:02:38.5904496Z"
Clearly 5904496
are seven digits. If there would have been 6 digits then I would have used the below code to convert this into datetime
object:
from datetime import datetime
datetime_object = datetime.strptime(startDateTime, '%Y-%m-%dT%H:%M:%S.%fZ')
But I get this error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/usr/lib/python3.6/_strptime.py", line 362, in _strptime
(data_string, format))
ValueError: time data '2020-09-16T10:02:38.5904496Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
How do I handle 7 digits in decimal part of seconds?
P.S: I know I can use python dateutil
library but I should know how to do this. I will really be thankful if you can shed some light on this.