package com.company; import java.time.DayOfWeek; import java.time.LocalDate; public class Main { public static void main(String[] args) { // write your code here LocalDate date=LocalDate.now(); int month=date.getMonthValue(); int today=date.getDayOfMonth(); date=date.minusDays(today-1);//set the start of the month DayOfWeek weekday=date.getDayOfWeek(); int value=weekday.getValue();//monday=1...sunday=7 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(); } }
用Java做一个简单的日历
最新推荐文章于 2024-09-02 08:51:16 发布