擅长:python、mysql、java
<p>这种方法有什么问题?</p>
<pre><code>>>> from datetime import datetime
>>> a = datetime.now()
>>> b = datetime.now() # after a few seconds
>>> delta = a-b
>>> delta.total_seconds()
-6.655989
</code></pre>
<p>请注意,<a href="http://docs.python.org/library/datetime.html#datetime.timedelta.total_seconds">^{<cd1>}</a>仅在Python 2.7<;中可用,但根据文档:</p>
<blockquote>
<p>Equivalent to (<code>td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6</code> computed with true division enabled.</p>
</blockquote>
<p>结果完全一样。</p>