title: How to correct calculate the running time
body: <p>I want to calculate the total running time of my program from start to end and refresh running time in JFrame, but when I run my program I get excess 70 years, 1 day and 2 hours. Why ? What wrong ?</p>
  
  <pre><code>private void setMachineTime(){
      Timer timer = new Timer();
      long startTime = new Date().getTime();
      timer.scheduleAtFixedRate(new TimerTask() {
         @Override
         public void run() {
             long endTime = new Date().getTime();
             long diffTime = endTime - startTime ;
             String time = new SimpleDateFormat("yy:mm:dd:HH:mm:ss").format(diffTime);
             System.out.println(time);
         }
      }, 0, 1000);
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/7sW0p.png" rel="nofollow">actual result</a></p>
  
  <p>UPD:
  I rewrote code with my own format time method. Now I got what I want. Thanks to all of you.</p>
  
  <pre><code>private void setMachineTime(){
      Timer timer = new Timer();
      long startTime = new Date().getTime();
      timer.scheduleAtFixedRate(new TimerTask() {
          @Override
          public void run() {
  
              long endTime = new Date().getTime();
              long diffTime = endTime - startTime;
              String diffSeconds = formatTime(diffTime / 1000 % 60);
              String diffMinutes = formatTime(diffTime / (60 * 1000) % 60);
              String diffHours = formatTime(diffTime / (60 * 60 * 1000) % 24);
              System.out.println(diffHours + ":" + diffMinutes + ":" + diffSeconds);
          }
      }, 0, 1000);
  }
  
  private String formatTime(long diff){
      long t;
      t = diff;
      if(t &lt; 10){
          return String.valueOf("0"+t);
      } else {
          return String.valueOf(t);
      }
  }
  </code></pre>