![]() |
The Java Developers Almanac 1.4 |
|
e375. Determining the Number of Days in a MonthThis example uses theCalendar 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
e374. Creating a Date Object for a Particular Date e376. Comparing Dates e377. Determining a Person's Age e378. Determining If a Year Is a Leap Year e379. Determining the Day-of-Week for a Particular Date
© 2002 Addison-Wesley. |