Java指定年月打印日历

	public static void printCalendar (int year, int month) {
		
		Calendar ca = Calendar.getInstance();
		TimeZone tz = ca.getTimeZone();
		System.out.println();
		System.out.print(tz.getDisplayName()+"\t\t");
		System.out.println(year+"年"+month+"月");
		System.out.println();
		ca.set(ca.YEAR, year);
		ca.set(ca.MONTH, month-1);
		//一个星期最大值为7,代表着星期六
		int maxDayOfWeek = ca.getMaximum(Calendar.DAY_OF_WEEK);
		//一个星期最小值为1,代表着星期一
		int minDayOfWeek = ca.getMinimum(Calendar.DAY_OF_WEEK);
		
		int max = ca.getMaximum(Calendar.DAY_OF_MONTH);
		
		System.out.println("一\t二\t三\t四\t五\t六\t日");
		for (int i = 0; i1 ) {
				sb.append(" \t").append(day);
			}else if(week == 7){
				if (day == 1) {
					sb.append(day).append("\r\n");
				}else {
					sb.append(" \t").append(day).append("\r\n");
				}
			}else {
				sb.append(day);
			}
			
			System.out.print(sb.toString());
		}
	}

长春Java5800培训班

你可能感兴趣的:(java)