title: Calculating time in Python output format
body: <p>In this thread we have a good solution
  <a href="https://stackoverflow.com/questions/3096953/how-to-calculate-the-time-interval-between-two-time-strings/54874257#54874257">How to calculate the time interval between two time strings</a></p>
  
  <p>But how I can edit the output format?
  From H:MM:SS to HH:MM, like 00:40 instead of 0:40:00</p>
  
  <pre><code>from datetime import datetime
  from datetime import timedelta
  
  T1 = input()
  T2 = input()
  format = '%H:%M'
  tdiff = datetime.strptime(T1, format) - datetime.strptime(T2, format)
  
  if tdiff.days &lt; 0:
      tdiff = timedelta(days = 0,
                  seconds = tdiff.seconds, microseconds = tdiff.microseconds)
  
  print(tdiff)
  </code></pre>
  
  <p>EDIT: Thank you. This code below quite works, but the only problem is 7:45 instead of 07:45 for example. The code below removes the problem of seconds at the end. Now I only don't know how to force 0 is front of &lt;10 hours format.</p>
  
  <pre><code>from datetime import datetime
  from datetime import timedelta
  
  T1 = input()
  T2 = input()
  format = '%H:%M'
  tdiff = datetime.strptime(T1, format) - datetime.strptime(T2, format)
  
  if tdiff.days &lt; 0:
      tdiff = timedelta(days = 0,
                  seconds = tdiff.seconds, microseconds = tdiff.microseconds)
  
  print(str(tdiff).rstrip("0").rstrip(":"))
  </code></pre>