<p>将日期/时间字符串解析为合适的日期时间对象,然后可以使用这些对象进行计算。在</p>
<p><a href="https://stackoverflow.com/questions/466345/converting-string-into-datetime">This post</a>解释了如何解析日期/时间字符串,或者您可以查看一下<a href="https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior" rel="nofollow noreferrer">documentation for the strptime() method</a>。在</p>
<p>对于计算,<a href="https://stackoverflow.com/questions/1750644/how-to-use-python-to-calculate-time">this post</a>中有示例,还有详细的文档<a href="https://docs.python.org/2/library/datetime.html" rel="nofollow noreferrer">here</a>。在</p>
<p>举个例子,类似这样的事情应该接近解决方案:</p>
<pre><code>from datetime import datetime
from datetime import timedelta
createdTime = datetime.strptime('2016-06-09T14:37:05.000+0200', '%Y-%m-%dT%H:%M:%S.%f')
resolvedTime = datetime.strptime('2016-06-10T10:53:12.000+0200', '%Y-%m-%dT%H:%M:%S.%f')
duration = resolvedTime - createdTime
</code></pre>
<p><em>持续时间</em>将是<em>timedelta</em>对象,您可以访问<em>持续时间.天</em>,<em>持续时间.秒</em>和<em>持续时间.微秒获取信息。在</p>
<p>strptime的一个缺点是它不支持解析时区,因此您必须先删除输入的那部分内容。或者,请参见<a href="https://stackoverflow.com/questions/12281975/convert-timestamps-with-offset-to-datetime-obj-using-strptime">this post</a>。在</p>