擅长:python、mysql、java
<p><a href="https://github.com/myusuf3/delorean" rel="nofollow"><em>Delorean</em></a>可以帮助您解析和转换为常规的<em>timedate</em>对象,因此您可以确定增量。在</p>
<p>以下代码采用日志中的格式,可以计算增量:</p>
<pre><code>from delorean import Delorean
from delorean import parse
st = parse("01/14/2015 09:16:15 PM")
end = parse("01/14/2015 09:16:20 PM")
diff = end.naive() - st.naive()
print diff
</code></pre>
<p>输出为:</p>
<blockquote>
<p>0:00:05</p>
</blockquote>
<p><code>st</code>和<code>end</code>都是时区<em>UTC</em>的<code>Delorean</code>对象,例如</p>
^{pr2}$
<p><code>diff</code>是一个<code>datetime.timedelta</code>对象,例如</p>
<pre><code>>>> diff = end.naive() - st.naive()
>>> type(diff)
<type 'datetime.timedelta'>
</code></pre>