1.LocalData,LocalTime, LocalDataTime
LocalDate now1 = LocalDate.now(); LocalTime now2 = LocalTime.now(); LocalDateTime now3 = LocalDateTime.now(); now1.toString(); now2.toString(); now3.toString(); 2021-11-06 20:17:05.697 2021-11-06T20:17:05.697 常用方法 1.LocalDate public int getYear(); 年 public int getMonthValue(); 月 public int getDayOfMonth(); 日 public int getDayOfYear(); 当前年的第几天 getDayOfWeek().getValue(); 当前周的第几天 2.LocalTime public int getHour(); 时 public int getMinute(); 分 public int getSecond(); 秒 public int getNano(); 毫秒 3.LocalDataTime 包含 LocalDate 与 LocalDataTime中的所有方法
2.DateTimeFormatter用法
1.日期转字符串
LocalDate localDate = LocalDate.now();
String format = localDate.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
LocalTime localTime = LocalTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm:ss");
String format = localTime.format(formatter);
LocalDateTime localDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
String format5 = localDateTime.format(formatter2);
2.字符串转日期
DateTimeFormatter dt = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate localDate = LocalDate.parse("2021/11/06",dt);
DateTimeFormatter dt = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime localDate = LocalTime.parse("21:30:45",dt);
DateTimeFormatter dt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // 24小时
LocalDateTime localDateTime = LocalDateTime.parse("2019-12-07 07:43:53",dt);



