How to calculate the time interval between two time strings

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

        import datetime
        
        day = int(input("day[1,2,3,..31]: "))
        month = int(input("Month[1,2,3,...12]: "))
        year = int(input("year[0~2020]: "))
        start_date = datetime.date(year, month, day)
        
        day = int(input("day[1,2,3,..31]: "))
        month = int(input("Month[1,2,3,...12]: "))
        year = int(input("year[0~2020]: "))
        end_date = datetime.date(year, month, day)
        
        time_difference = end_date - start_date
        age = time_difference.days
        print("Total days: " + str(age))
    

提交回复
热议问题