简体   繁体   English

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

[英]How to get the duration time in Python?

See my sample code: 查看我的示例代码:

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?

I read https://docs.python.org/2/library/time.html but don't find a method. 我阅读了https://docs.python.org/2/library/time.html,但是没有找到方法。

Thank you! 谢谢!

This question is closed, thanks so much to pjz and Robᵩ! 这个问题已经解决,非常感谢pjz和Robᵩ!

A perfect solution is posted in http://ideone.com/J8VwNl 完美的解决方案发布在http://ideone.com/J8VwNl

您要使用datetime模块,而不要使用time模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM