I am trying to do something very simple, take a Date and get the first day of the next month from it. I have tried using Calendar. Here date is of type Calendar.
Calendar nextMonthFirst = (Calendar)date.clone();
int year = date.get(Calendar.YEAR);
int month = date.get(Calendar.MONTH);
nextMonthFirst.clear();
nextMonthFirst.set(year, month+1,1);
nextMonthFirst.add(Calendar.DAY_OF_MONTH, 0);
return nextMonthFirst
When I use date as cal.set(2016,11,30); I get the output as 2017-01-01 instead of 2016-12-01. Any idea what I am doing wrong?