1. 程式人生 > >打印日歷

打印日歷

得到 == while pri print stat 日歷 () pub

 
 1 import java.io.IOException;
 2 import java.time.DayOfWeek;
 3 import java.time.LocalDate;
 4 
 5 public class test {
 6     public static void main(String[] args) throws IOException {
 7     LocalDate date = LocalDate.now();
 8 
 9     int month = date.getMonthValue();
10     int today = date.getDayOfMonth();
11 12 date = date.minusDays(today-1);//得到today-1天前的日期 13 DayOfWeek weekday = date.getDayOfWeek(); 14 int value = weekday.getValue(); 15 16 System.out.println("Mon Tue Wed Thu Fri Sat Sun"); 17 for(int i =1;i<value; i++) 18 System.out.print(" "); 19 20 while(date.getMonthValue()==month) {
21 System.out.printf("%3d", date.getDayOfMonth()); 22 if (date.getDayOfMonth() == today) 23 System.out.print("*"); 24 else 25 System.out.print(" "); 26 date = date.plusDays(1); 27 if (date.getDayOfWeek().getValue() == 1) 28 System.out.println();
29 } 31 } 32 }

2018-07-29 14:39:35

打印日歷