Date及DateFormat用法
Date 与DateFormat之间的转化
String <————>Date
Date与Calendar 之间的转化
Long<————>Date
日历小程序
Scanner input=new Scanner(System.in); String str=input.nextLine(); String time=str; DateFormat date=new SimpleDateFormat("yyyy-MM-dd"); Date date1=date.parse(time); Calendar cal=new GregorianCalendar(); cal.setTime(date1); int day_month=cal.get(Calendar.DAY_OF_MONTH); int total=cal.getActualMaximum(Calendar.DATE); cal.set(Calendar.DATE, 1); int weekday=cal.get(Calendar.DAY_OF_WEEK); System.out.println(total); System.out.println(weekday); System.out.println("日\t一\t二\t三\t四\t五\t六\n"); for(int i=1;i<weekday;i++){ System.out.print("\t"); } for(int i=1;i<=total;i++){ if(i==day_month){ System.out.print("*"); } System.out.print(i+"\t"); if(7==cal.get(Calendar.DAY_OF_WEEK)){ System.out.println(); } cal.add(Calendar.DATE, 1); }