datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z')
问题 I've been trying to convert this specific date format to a string in Python like so: datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z') But it doesn't work. What am I doing wrong? 回答1: Solution for Python 2.7 From the comments it became clear that OP needs a solution for Python 2.7. Apparently, there's no %z in strptime for python 2.7 even though the documentation claims the contrary, the raised error is ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S