I want to get the last month End date, I am getting the current month and recuding it by one and setting that month value. But Calender.set(Calender.Month, lastMonth) doesnt work for only a specific date.

```
public static String getLastMonthEndDate(Date nowDate, String dateFormat) 
{
    final String METHOD_NAME = "getLastMonthEndDate" ;

    SimpleDateFormat formatedDate = new SimpleDateFormat(dateFormat);

    Calendar calendar = new GregorianCalendar(2014, Calendar.OCTOBER, 31); // Hard coded as 2014, oct 31st for the sake of example.
    //calendar.setTime(nowDate);
    System.out.println(calendar.getTime());
    if(calendar.get(Calendar.MONTH) == Calendar.JANUARY)
    {
        calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 1);
    }

    //System.out.println("calendar.get(Calendar.MONTH) -1 : " + (calendar.get(Calendar.MONTH) -1));
    int lastMonth = (calendar.get(Calendar.MONTH) -1);
    System.out.println("Last month : "+lastMonth);
    calendar.set(Calendar.MONTH, lastMonth);
    //System.out.println(calendar.getTime());
    //System.out.println("(calendar.get(Calendar.MONTH) : " + calendar.get(Calendar.MONTH));
    System.out.println("calendar.getActualMaximum(Calendar.DAY_OF_MONTH) : " + calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    System.out.println("calendar.getTime() : " + calendar.getTime());

    return formatedDate.format(calendar.getTime());
}

public static void main(String[] args)
{

     Date dCurrentDate = getCurrentDate();
     String strLastMonthEndDateInYYYY = getLastMonthEndDate(dCurrentDate, "MM/dd/yyyy");
     System.out.println("strLastMonthEndDateInYYYY : "+strLastMonthEndDateInYYYY);

}

```

The Below is the output which i got

```
output : 

Fri Oct 31 00:00:00 IST 2014

Last month : 8

calendar.getActualMaximum(Calendar.DAY_OF_MONTH) : 31

calendar.getTime() : Wed Oct 01 00:00:00 IST 2014

strLastMonthEndDateInYYYY : 10/01/2014

```

I don't know what where the mistake is. Please help.