1

From some sensor I obtained very precise time measurement given as this:

time_str = '2019-07-03T20:03:51.520273066Z'

Using the datetime library, I'm trying to convert it to datetime object:

time_obj = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S.%fZ")

Which results in:

ValueError: time data '2019-07-03T20:03:51.520273066Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

I've noticed and later read from documentation of strptime(), that the ".%f" symbol is for formatting maximum of 6 decimal numbers. Therefore, following code works perfectly:

time_str = '2019-07-03T20:03:51.5202Z'
time_obj = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S.%fZ")

My question - is there a possibility of converting such precise measurement as datetime object, besides some direct manipulations on the string itself (perhaps without loosing the accuracy)?

errno98
  • 312
  • 2
  • 12

0 Answers0