import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.GregorianCalendar;public class Work2 { /** * @param args */public static void main(String[] args) { //变动时间:用来打印 GregorianCalendar change=new GregorianCalendar(); for (int i = 0; i < 12; i++) { change.set(GregorianCalendar.YEAR, 2013); change.set(GregorianCalendar.MONTH, i); change.set(GregorianCalendar.DAY_OF_MONTH, 1); //打印月份 System.out.println((i+1)+"月"+"\n"+"-----------------------------------------------------"); //打印抬头 System.out.println("日\t一\t二\t三\t四\t五\t六"); //打印空列 int num=change.get(GregorianCalendar.DAY_OF_WEEK); printNullCol(num-1); //打印具体某一天 while(getMonth(change)==(i)){ //打印当前的天 System.out.print(getDay(change)+"\t"); //换行 if(change.get(GregorianCalendar.DAY_OF_WEEK)==7){ System.out.println(); } //累加天 change.add(GregorianCalendar.DAY_OF_MONTH, 1); } System.out.println(); } } /* * 根据GregorianCalendar得到Day */ public static int getDay(GregorianCalendar gc){ return gc.get(GregorianCalendar.DAY_OF_MONTH); } /* * 根据GregorianCalendar得到Month */ public static int getMonth(GregorianCalendar gc){ return gc.get(GregorianCalendar.MONTH); } /* * 打印空列 */ public static void printNullCol(int num){ for (int i = 0; i < num; i++) { System.out.print("\t"); } }}