How to calculate the time interval between two time strings

前端 未结 12 2471
生来不讨喜
生来不讨喜 2020-11-22 12:03

I have two times, a start and a stop time, in the format of 10:33:26 (HH:MM:SS). I need the difference between the two times. I\'ve been looking through documentation for

12条回答
  •  醉酒成梦
    2020-11-22 12:36

    Try this -- it's efficient for timing short-term events. If something takes more than an hour, then the final display probably will want some friendly formatting.

    import time
    start = time.time()
    
    time.sleep(10)  # or do something more productive
    
    done = time.time()
    elapsed = done - start
    print(elapsed)
    

    The time difference is returned as the number of elapsed seconds.

提交回复
热议问题