For reference, you can also see: http://stackoverflow.com/questions/8906926/formatting-python-timedelta-objects which shows a similar approach. The accepted solution there uses the divmod() function to simplify a little bit of the math.