Search code examples
pythondatetimestrptime

ValueError: time data '2015-06-29-16:27:07.157+00:00I-----' does not match


I think I'm missing something but I really tried all possible combinations for datetime format. This one was my latest try and it throws the same error :

datetime.strptime('2015-06-29-16:27:07.157+00:00I-----', "%Y-%m-%d-%H:%M:%S+%I-----")

Any suggestion would be appreciated


Solution

  • As your string format is not a valid date time you can just put 00:00 directly on strptime format :

    >>> datetime.strptime('2015-06-29-16:27:07.157+00:00I-----', "%Y-%m-%d-%H:%M:%S.%f+00:00I-----")
    datetime.datetime(2015, 6, 29, 16, 27, 7, 157000)
    

    For more details have a look at https://docs.python.org/2/library/datetime.html