Calculate time between time-1 to time-2?

前端 未结 4 659
夕颜
夕颜 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:05

    Simplest and most direct may be something like:

    def getime(prom):
      """Prompt for input, return minutes since midnight"""
      s = raw_input('Enter time-%s (hh:mm): ' % prom)
      sh, sm = s.split(':')
      return int(sm) + 60 * int(sh)
    
    time1 = getime('1')
    time2 = getime('2')
    
    diff = time2 - time1
    
    print "Difference: %d hours and %d minutes" % (diff//60, diff%60)
    

    E.g., a typical run might be:

    $ python ti.py 
    Enter time-1 (hh:mm): 01:12
    Enter time-2 (hh:mm): 18:59
    Difference: 17 hours and 47 minutes
    

提交回复
热议问题