Python time objects with more than 24 hours
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.
timedelta is indeed what you want. Here is a more complete example that does what you asked.
>>> import datetime
>>> a = datetime.timedelta(hours=36)
>>> b = datetime.timedelta(hours=4, minutes=46, seconds=23)
>>> c = a - b
>>> print c
1 day, 7:13:37
What you need is the timedelta object: http://docs.python.org/library/datetime.html#timedelta-objects
36 hours:
d = timedelta(hours=36)
精彩评论