title: Time difference between two times
body: <p>I want to display the difference between two times in hh:mm format.   </p>
  
  <p>The first time is from a database and the second time is the system time. Time difference is updated every second.</p>
  
  <p>How can I do that?</p>
  
  <p>Currently I'm  using two manual time if this works perfectly then I implement it into my apps.</p>
  
  <pre><code>public class MainActivity extends Activity 
  {
      TextView mytext;
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Timer updateTimer = new Timer();
          updateTimer.schedule(new TimerTask() 
          {
              public void run() 
              {
                  try 
                  {
                      TextView txtCurrentTime= (TextView)findViewById(R.id.mytext);
                      SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss aa");
                      Date date1 = format.parse("08:00:12 pm");
                      Date date2 = format.parse("05:30:12 pm");
                      long mills = date1.getTime() - date2.getTime();
                      Log.v("Data1", ""+date1.getTime());
                      Log.v("Data2", ""+date2.getTime());
                      int hours = (int) (mills/(1000 * 60 * 60));
                      int mins = (int) (mills % (1000*60*60));
  
                      String diff = hours + ":" + mins; // updated value every1 second
                      txtCurrentTime.setText(diff);
                  } 
                  catch (Exception e) 
                  {
                      e.printStackTrace();
                  }
              }
  
          }, 0, 1000);
      }
  }
  </code></pre>