超过24小时的Python时间对象
我的 Linux 超时时间为 hh:mm:sec,但 hh 可能大于 24 小时。因此,如果时间为 1 天 12 小时,则为 36:00:00。有没有办法采用这种格式并轻松制作时间对象?
我真正想做的是获取所需的时间,即 36:00:00,以及它运行的时间 4:46:23,然后减去两者以获得剩余时间。我认为时间增量可能是在 Python 中执行此操作的最方便的方法,但我也愿意接受其他建议。
谢谢。
I have a time out of Linux that is in hh:mm:sec, but the hh can be greater than 24 hours. So if the time is 1 day 12 hours, it would be 36:00:00. Is there a way to take this format and easily make a time object?
What I would really like to do is take the the required time i.e. 36:00:00, and the time that it has been running 4:46:23, and subtract the two to get the time remaining. I figured time delta might be the most convenient way to do this in Python, but I'd also be open to other suggestions.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
timedelta 确实是你想要的。这是一个更完整的示例,可以满足您的要求。
timedelta is indeed what you want. Here is a more complete example that does what you asked.
您需要的是 timedelta 对象: http://docs.python.org/library /datetime.html#timedelta-objects
36 小时:
What you need is the timedelta object: http://docs.python.org/library/datetime.html#timedelta-objects
36 hours: