title: Doubt in getting yesterday's date using java
body: <p>I want to get yesterday's date using java. I have used the following code but it is giving different date each time, Please check whether the code has to be change anywhere. Thanks in advance.</p>
  
  <pre><code> SimpleDateFormat formatter= 
          new SimpleDateFormat("yyyy-mm-dd ");
      Calendar currentDate = Calendar.getInstance();
      String previous = formatter.format(currentDate.getTime())+ "00:00:00.000000000";
      System.out.println("previous ="+previous);
      currentDate.add(Calendar.DATE, -1);
      String previousDate = formatter.format(currentDate.getTime())+ "00:00:00.000000000";
      Timestamp updateTimestamp = Timestamp.valueOf(previousDate);
      System.out.println("Update date ="+updateTimestamp);
  </code></pre>
  
  <p>This is the output i got when i ran lastly<br>
  <strong>previous =2010-15-11 00:00:00.000000000 <br>
  Update date =2011-03-10 00:00:00.0</strong></p>