Trying to run this code it was working perfectly fine till OCT but in NOV it is like
firstdate 2019-12-01 & lastdate 2020-12-31
public class Test1 {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 1);
String date;
calendar.set(Calendar.DATE,calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
Date nextMonthFirstDay = calendar.getTime();
date=new SimpleDateFormat("YYYY-MM-dd").format(nextMonthFirstDay).toLowerCase();
System.out.println("firstdate "+ date);
calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Date nextMonthLastDay = calendar.getTime();
date=new SimpleDateFormat("YYYY-MM-dd").format(nextMonthLastDay).toLowerCase();
System.out.println("lastdate "+date);
}
}
I don't know why it is showing like this.. Is it a fault or bug in java ?
Change your date format to yyyy-MM-dd (notice lowercase for year)
They both represent a year but yyyy represents the calendar year while YYYY represents the year of the week.
So something like...
Hope it helps!