/** * @param args */ public static void main(String[] args) { GregorianCalendar d = new GregorianCalendar(); int today = d.get(Calendar.DAY_OF_MONTH); // current day int month = d.get(Calendar.MONTH); // current month String[] weekdayNames = new DateFormatSymbols().getShortWeekdays(); // print first line for(int i =1; i < weekdayNames.length; i++) System.out.printf("%4s", weekdayNames[i]); System.out.println(); // print blank space at first line d.set(Calendar.DAY_OF_MONTH, 1); int weekday = d.get(Calendar.DAY_OF_WEEK); for(int i = 0; i < weekday; i++) { System.out.print(" "); } //print day number while(d.get(Calendar.MONTH) == month) { System.out.printf("%3s", d.get(Calendar.DAY_OF_MONTH)); if(d.get(Calendar.DAY_OF_MONTH) == today) System.out.print("*"); else System.out.print(" "); d.add(Calendar.DAY_OF_MONTH, 1); weekday = d.get(Calendar.DAY_OF_WEEK); if(weekday == 7) System.out.println(); } }
java打印一个月日历,JAVA 打印当前月日历
最新推荐文章于 2022-06-14 15:51:33 发布