Python time objects with over 24 hours

I have time from Linux that is in hh: mm: sec, but hh can be more than 24 hours. Therefore, if the time is 1 day 12 hours, it will be 36:00:00. Is there a way to accept this format and easily create a time object?

What I really would like to do is take the required time, that is, 36:00:00, and the time when it was started at 4:46:23, and subtract them to get the remaining time. I decided that a temporary delta might be the most convenient way to do this in Python, but I will also be open to other suggestions.

Thanks.

+7
python time timedelta
source share
2 answers

timedelta is really what you want. Here is a more complete example that does what you requested.

>>> 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 
+11
source share

You need a timedelta object: http://docs.python.org/library/datetime.html#timedelta-objects

36 hours:

 d = timedelta(hours=36) 
+9
source share

All Articles