import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class CalendarUtil {
public void printDate(Date date){
Calendar cal=Calendar.getInstance();
cal.set(date.getYear()+1900, date.getMonth(), date.getDate());
cal.roll(Calendar.DATE, -1);
int dateNum=cal.get(cal.DATE);
cal.set(Calendar.DATE, 1);
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));
int day=cal.get(Calendar.DAY_OF_WEEK);
System.out.println("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
int j=0;
for (int i = 0; i < dateNum; i++) {
if (j%7==0) {
System.out.println("\n");
}
if (i==0) {
switch (--day) {
case 1:
System.out.print("\t");
j++;
break;
case 2:
System.out.print("\t\t");
j+=2;
break;
case 3:
System.out.print("\t\t\t");
j+=3;
break;
case 4:
System.out.print("\t\t\t\t");
j+=4;
break;
case 5:
System.out.print("\t\t\t\t\t");
j+=5;
break;
case 6:
System.out.print("\t\t\t\t\t\t");
j+=6;
break;
default:
break;
}
}
System.out.print((i+1)+"\t");
j++;
}
}
public static void main(String[] args) {
CalendarUtil util=new CalendarUtil();
try {
util.printDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-07-01"));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}