Measuring elapsed time with the Time module

前端 未结 10 849
执念已碎
执念已碎 2020-12-02 03:13

With the Time module in python is it possible to measure elapsed time? If so, how do I do that?

I need to do this so that if the cursor has been in a widget for a c

10条回答
  •  温柔的废话
    2020-12-02 04:08

    For a longer period.

    import time
    start_time = time.time()
    ...
    e = int(time.time() - start_time)
    print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60))
    

    would print

    00:03:15
    

    if more than 24 hours

    25:33:57
    

    That is inspired by Rutger Hofste's answer. Thank you Rutger!

提交回复
热议问题