擅长:python、mysql、java
<p>您的错误<code>module 'datetime' has no attribute 'strftime'</code>表明这不是导入的问题,而是如何调用<code>strftime()</code>方法的问题。</p>
<p><code>strftime()</code>是<code>datetime</code>类上的一个方法(它是<code>datetime</code>模块的一部分),因此需要一个实例化的<code>datetime</code>对象来调用它。例如:</p>
<pre><code># import datetime class from the datetime module:
from datetime import datetime
# instantiate a new datetime object:
a = datetime(12, 10, 30, 11, 23, 45)
# call the strftime() method on the object:
print(a.strftime("%H:%M:%S %Z"))
# 11:23:45
</code></pre>