Trying to convert str to date ,e.g '2017-8-27'
my code:
from datetime import datetime as dt
import datetime, collections
date = dt.strptime('2017-8-27', '%Y-%-m-%-d')
But I see the following message:
'-' is a bad directive in format '%Y-%-m-%-d'
And don't understand what is incorrect. How can I solve it?
Thanks in advance,
答案 0 :(得分:3)
The % should be followed by a format specifier.
The correct format string is '%Y-%m-%d'