如何计算Python的时间差?
示例:
9:43-17:27-在那段时间之间经过了几小时?
Example:
9:43 - 17:27 - how many hours and minutes elapsed between those times ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
示例:
9:43-17:27-在那段时间之间经过了几小时?
Example:
9:43 - 17:27 - how many hours and minutes elapsed between those times ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
这是获取总分钟数的一种方法:
输出:
390.0
Here is one approach to get the number of total minutes:
Output:
390.0
如果您知道时间段永远不会跨越午夜,那么您可以简单地按时间分开时间字符串。Split(“:”),并用小时和分钟自己进行数学。
但是,正确的解决方案是导入DateTime模块并计算时间码。
这个示例可以凝结。我故意将其冗长地说明,而不必确切地知道您如何获得投入:
If you know that the time periods will never span midnight, then you could simply split the time strings with time.split(":") and do the math yourself with the hours and minutes.
However, the correct solution would be to import the datetime module and calculate the timedelta.
This example could be condensed. I intentionally made it verbose without knowing exactly how you're getting your inputs: