Brainstorm's snippets (1/278)

  elapsed_time():: Human readable time interval between two values of time.time()

import math
import time

def elapsed_time(t0, t1, with_milliseconds=False):
    """
    Human readable time interval between two values of time.time()
    """
    milliseconds, seconds = math.modf(t1 - t0)
    dt = time.strftime("%H:%M:%S", time.gmtime(seconds))
    if with_milliseconds:
        dt += ('%.3f' % milliseconds)[1:]
    return dt