'-' is a bad directive in format '%Y-%-m-%-d' - python/django

时间:2017-08-04 13:15:03

标签: python

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,

1 个答案:

答案 0 :(得分:3)

The % should be followed by a format specifier.

The correct format string is '%Y-%m-%d'