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.
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);
This is the output i got when i ran lastly
previous =2010-15-11 00:00:00.000000000
Update date =2011-03-10 00:00:00.0