def format_time_diff(start=None, end=None):
 if (end is None):
  end = datetime.datetime.now()
 diff = (end - start)
 (minutes, seconds) = divmod(diff.seconds, 60)
 (hours, minutes) = divmod(minutes, 60)
 days = diff.days
 output = []
 written = False
 if days:
  written = True
  output.append(('%dd' % days))
 if (written or hours):
  written = True
  output.append(('%dh' % hours))
 if (written or minutes):
  output.append(('%dm' % minutes))
 output.append(('%ds' % seconds))
 return ':'.join(output)

def format_time_diff ( start = None , end = None ) : if ( end is None ) : end = datetime . datetime . now ( ) diff = ( end - start ) ( minutes , seconds ) = divmod ( diff . seconds , 60 ) ( hours , minutes ) = divmod ( minutes , 60 ) days = diff . days output = [ ] written = False if days : written = True output . append ( ( '%dd' % days ) ) if ( written or hours ) : written = True output . append ( ( '%dh' % hours ) ) if ( written or minutes ) : output . append ( ( '%dm' % minutes ) ) output . append ( ( '%ds' % seconds ) ) return ':' . join ( output )
formats the difference between two times as xd:xh:xm:xs .