0

I'm struggling to convert ISO 8601 datetime coming from angular datetime component on the client side in the python backend. The date is coming from the angular-material-datetimepicker library in this format: '2016-10-24T10:00:00.000Z'. How do I convert to a datetime object to send to the datastore? I'm using Google App Engine. Here's what I've tried fiddling with in pycharm among other things I've found on other forums;

works

>>> datetime.datetime.strptime('2016-10-24T10:00:00Z', '%Y-%m-%dT%H:%M:%SZ')
datetime.datetime(2016, 10, 24, 10, 0)

does not work

datetime.datetime.strptime('2016-10-24T10:00:00.000Z', '%Y-%m-%dT%H:%M:%SZ')

enter image description here

As seen above, the first command with the 'nanoseconds i think?' does not work. That is the actual format angular sends through. When I remove .000 it works as seen in the second command. What method call should I execute on the first date for it to work? Also I tried;

>>> datetime.datetime.strptime('2016-10-24T10:00:00.000Z', '%Y-%m-%dT%H:%M:%S%fZ')
colin_dev256
  • 805
  • 2
  • 16
  • 36
  • 1
    Please insert your output and code as `code` so that people can search for it and use it, instead of pasting a screenshot. – Daniel Nov 23 '16 at 10:36
  • Why is that strange? You're missing the format for the microseconds – Tim Nov 23 '16 at 10:39

0 Answers0