title: Trying to update Date and Time in a loop
body: <p>I want to print and update the date and time simultaneously. The following code only takes the time once and prints the same time 40 times. How can I update the time while printing it?</p>
  
  <pre><code>public class Dandm {
      public static void main(String args[]) {
          DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
          Date date = new Date();
          String time = df.format(date);
          int i;
          for (i = 40; i &gt; 0; i--) {
              System.out.println(date);
              try {
                  Thread.sleep(500);
              } catch (InterruptedException e){}
          }
      }
  }
  </code></pre>