The Java Calendar class provides many helpful methods for modifying Date objects. Here you will find a short code snippet for obtaining the last day of the month. To utilize the code please don’t forget to import the java.util.Calendar class or which ever Calendar you utilize. How the snippet works is it utilizes the getActualMaximum function which returns the max value for a field based on the current settings of the Calendar.
Calendar cal = Calendar.getInstance();
cal.set( Calendar.MONTH, 11 );
cal.set( Calendar.DATE, cal.getActualMaximum(Calendar.DAY_OF_MONTH) );
Comments & Questions
Add Your Comment