Python format timedelta greater than 24 hours for display only containing hours?
May be defining your class that inherits datetime.timedelta
will be a little more elegant
class mytimedelta(datetime.timedelta):
def __str__(self):
seconds = self.total_seconds()
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60
str = '{}:{}:{}'.format(int(hours), int(minutes), int(seconds))
return (str)
td = mytimedelta(hours=36, minutes=10, seconds=10)
>>> str(td)
prints '36:10:10'