Needs to get previous date from the given date
Hi,
I have a requirement to get the previous day for a given date. Please find the code below. It is giving previous day of the current date but i need the previous day of the given date.
Kindly help in this,
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
GregorianCalendar gc = new GregorianCalendar();
try{
gc.setGregorianChange(sdfInput.parse("22-JAN-2007"));
}catch(ParseException e){
System.out.println(e.getMessage());
}
gc.add(Calendar.DATE,-1);
Date d = gc.getTime();
System.out.println(sdf.format(d));
Expected output : 21-JAN-2007
Resultant output : current date - 1 i.e suppose today is 22nd April 2007, then it is giving 21-Apr-2007.
Regards
Bala
|