Determining the Number of Days in a Month

This example uses the Calendar class to determine the number of days in the month of a particular year.
// Create a calendar object of the desired month Calendar cal = new GregorianCalendar(1999, Calendar.FEBRUARY, 1); // Get the number of days in that month int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28 // Try month in a leap year cal = new GregorianCalendar(2000, Calendar.FEBRUARY, 1); days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 29

Comments

18 Mar 2010 - 11:40pm by JavaMagneto (not verified)

Will it work ? Have you checked in 1.5

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.