- import java.util.Calendar;
- /**
- * 功能概述:计算指定年月的天数和周数<br>
- */
- public class Test{
- public static void main(String[] args) {
- Calendar c = Calendar.getInstance();
- c.set(Calendar.YEAR, 2010); // 2010年
- c.set(Calendar.MONTH, 5); // 6 月
- System.out.println("------------" + c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月的天数和周数-------------");
- System.out.println("天数:" + c.getActualMaximum(Calendar.DAY_OF_MONTH));
- System.out.println("周数:" + c.getActualMaximum(Calendar.WEEK_OF_MONTH));
- }
- }