public class VisualCalendar { public static void main(String[] args){ System.out.println("请输入日期(按照格式:2630-3-18)"); Scanner scanner = new Scanner(System.in); String temp = scanner.nextLine(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { Date date = format.parse(temp); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); int day = calendar.get(Calendar.DATE); calendar.set(Calendar.DATE, 1); int maxDate = calendar.getActualMaximum(Calendar.DATE); System.out.println("日 一 二 三 四 五 六"); for(int i=0;i<calendar.get(Calendar.DAY_OF_WEEK)-1;i++){ System.out.print(" "); } int j=0; //可视化日历程序 for(int i=1;i<=maxDate;i++){ if(i==day){ System.out.print('*'); } System.out.print(i+" "); int w = calendar.get(Calendar.DAY_OF_WEEK); if(w == Calendar.SATURDAY){ System.out.print(' '); } j++; calendar.add(Calendar.DATE, 1); } } catch (ParseException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } }