<p>我正在尝试将“DD-m m-YYYY”格式的字符串转换为datetime对象。如果日期中的日期是个位数,我希望输出中的日期整数由个位数组成。例如,在转换为datetime对象而不是“2014年5月1日”之后,输入“2014年5月1日”应转换为“2014年5月1日”。</p>
<p>为此,我使用了%e格式来转换输出日期中的日期。下面是相同的代码:</p>
<pre><code>import datetime
from datetime import timedelta
s = "1 July 2013"
d = datetime.datetime.strptime(s, "%e %B %Y")
print d.strftime("%e %B %Y")
</code></pre>
<p>但是,我得到了以下错误:</p>
<pre><code>ValueError: 'e' is a bad directive in format '%e %B %Y'
</code></pre>
<p>格式有什么问题?如果有帮助的话,我正在使用Python2.7。</p>