How to calculate the time interval between two time strings

前端 未结 12 2421
生来不讨喜
生来不讨喜 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:51

    This site says to try:

    import datetime as dt
    start="09:35:23"
    end="10:23:00"
    start_dt = dt.datetime.strptime(start, '%H:%M:%S')
    end_dt = dt.datetime.strptime(end, '%H:%M:%S')
    diff = (end_dt - start_dt) 
    diff.seconds/60 
    

    This forum uses time.mktime()

提交回复
热议问题