如何在Python中获取持续时间?

时间:2014-11-10 15:54:22

标签: python time

请参阅我的示例代码:

import time

start_time_string = "2013-05-24 17:51:06"
end_time_string = "2013-05-24 17:59:33"

start_time_stamp = time.mktime(time.strptime(start_time_string, "%Y-%m-%d %H:%M:%S"))
start_time_struct = time.localtime(start_time_stamp)

end_time_stamp = time.mktime(time.strptime(end_time_string, "%Y-%m-%d %H:%M:%S"))
end_time_struct = time.localtime(end_time_stamp)

# what's the next step to get duration time, like x minute?

我看过https://docs.python.org/2/library/time.html,但找不到方法。

谢谢!

这个问题已经结束了,非常感谢pjz和Robᵩ!

完美的解决方案发布在http://ideone.com/J8VwNl

1 个答案:

答案 0 :(得分:1)

您想使用datetime模块,而不是time模块。