Code:
Calendar calendar = Calendar.getinstance ();
Calendar.set (Calendar.month, month-1);
Calendar.set (Calendar.year, year);
System.out.println (Calendar.get (Calendar.month));
Return Calendar.getactualmaximum (Calendar.day_of_month);
The result of the test is that when the actual number of days for the month parameter month is less than 31 days, the printed month result is plus 1
Information found on the Internet: http://topic.csdn.net/u/20071030/11/cc414f35-5d1b-4bae-a1c3-21e9a7fa662e.html
My test time is 2011/10/31, the code does not set Calendar.day_of_month, the date is the current 31st, and for example, September is 30 days, the month automatically add 1, the result calendar date is 2011/10/01; If the parameter passed is February , February 2011 A total of 28 days, that calendar date is 2011/03/03
Workaround:
Calendar calendar = Calendar.getinstance ();
Calendar.set (Calendar.day_of_month, 1); Set Date
calendar.set (Calendar.month, month-1);
Calendar.set (Calendar.year, year); Return
Calendar.getactualmaximum (calendar.day_of_month)