Calculating Elapsed Time

skip at pobox.com skip at pobox.com
Tue Dec 6 15:46:00 EST 2005


    Jean> How do I calculate the elapsed time?

Where t1_s and t2_s reference time strings in the format you describe:

    import datetime
    import time

    fmt = "%b %d %Y  %H:%M:%S"

    t1 = datetime.datetime(*time.strftime(t1_s, fmt)[:6])
    t2 = datetime.datetime(*time.strftime(t2_s, fmt)[:6])
    dt = t2 - t1

should do the trick.

Skip




More information about the Python-list mailing list