打印日历
Posted confusion
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打印日历相关的知识,希望对你有一定的参考价值。
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
以上是关于打印日历的主要内容,如果未能解决你的问题,请参考以下文章