1 package guyu.day0831; 2 3 import java.text.SimpleDateFormat; 4 import java.time.DayOfWeek; 5 import java.time.LocalDate; 6 import java.util.Date; 7 8 /** 9 * @Author: Fred 10 * @Date: 2020/8/31 9:28 11 */ 12 public class Demo01 { 13 public static void main(String[] args) { 14 15 //获取当前的年月日时间(24小时制且区分上下午) 16 System.out.println("当前时间为:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss a").format(new Date())); 17 18 System.out.println("--------------日历----------------"); 19 20 //日历表 21 LocalDate date = LocalDate.now(); // 获取当前日期 22 int month = date.getMonthValue(); // 获取当前日期是几月 23 int today = date.getDayOfMonth(); // 获取当前日期是这个月的第几天 24 25 date = date.minusDays(today - 1); 26 DayOfWeek weekday = date.getDayOfWeek(); 27 int value = weekday.getValue(); // 算出来这个月的第一天是星期几 28 29 System.out.println(" Mon Tue Wed Thu Fri Sat Sun "); 30 for (int i = 1; i < value; i++) 31 System.out.print(" "); 32 33 while (date.getMonthValue() == month) { 34 System.out.printf("%3d", date.getDayOfMonth()); 35 if (date.getDayOfMonth() == today) 36 System.out.print("*"); 37 else 38 System.out.print(" "); 39 40 date = date.plusDays(1); 41 if (date.getDayOfWeek().getValue() == 1) 42 System.out.println(); 43 } 44 if (date.getDayOfWeek().getValue() != 1) 45 System.out.println(); 46 System.out.println(" "); 47 // System.out.println("找找加"*"的今天哦!"); 48 } 49 50 }
故屿γ