Calculate time between time-1 to time-2?

前端 未结 4 597
夕颜
夕颜 2021-02-08 13:28
enter time-1 // eg 01:12
enter time-2 // eg 18:59

calculate: time-1 to time-2 / 12 
// i.e time between 01:12 to 18:59 divided by 12

How can it be don

4条回答
  •  悲哀的现实
    2021-02-08 14:08

    The datetime and timedelta class from the built-in datetime module is what you need.

    from datetime import datetime
    
    # Parse the time strings
    t1 = datetime.strptime('01:12','%H:%M')
    t2 = datetime.strptime('18:59','%H:%M')
    
    # Do the math, the result is a timedelta object
    delta = (t2 - t1) / 12
    print(delta.seconds)
    

提交回复
热议问题