I have a calendar initially set to 2019-11-01, that i want to set to the first date and the last date of month using the:
cal.set(int field,int value)
And for the field i use either:
Calendar.DATE or Calendar.DAY_OF_MONTH
But system on sysout shows that it is setting the Calendar.YEAR instead
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));
cal.set(cal.get(Calendar.DAY_OF_MONTH),1);
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));
cal.set(cal.get(Calendar.DAY_OF_MONTH),cal.getActualMaximum(Calendar.DAY_OF_MONTH));
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));
Sysout:
2019-11-01
0001-11-01
0030-11-01