java输出月的日历控制台

    LocalDate date=LocalDate.now();
        int month=date.getMonthValue();
        int today=date.getDayOfMonth();
        date=date.minusDays(today-1);
        DayOfWeek weekDay= date.getDayOfWeek();
        int value=weekDay.getValue();
        
        System.out.println("Mon Tue Wed Thu Fri Sat Sun");
        for (int i = 1; i < value; i++) {
            System.out.print("    ");
        }
        while (date.getMonthValue()==month) {
            
            System.out.printf("%3d", date.getDayOfMonth());
            if (date.getDayOfMonth()==today) {
                System.out.print("*");
            }
            else {
                System.out.print(" ");
            }
            date=date.plusDays(1);
            if (date.getDayOfWeek().getValue()==1) {
                System.out.println();
            }
        }
        
        if (date.getDayOfWeek().getValue()!=1) {
            System.out.println();
        }

 

posted @ 2019-05-07 16:53  白羽轻飘  阅读(411)  评论(0编辑  收藏  举报