1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import java.util.Calendar; /** * 功能概述:计算指定年月的天数和周数<br> * 创建时间:2010-5-17 下午05:25:58<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)); } } |