LocalDate只能表示日期
LocalDate date = LocalDate.now();
System.out.println(date.toString());
我们可以format它
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
System.out.println(date.format(formatter));
LocalTime只能表示时间
LocalTime time=LocalTime.now();
System.out.println(time.toString());
我们可以format它
LocalTime time=LocalTime.now();
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("HH:mm:ss");
System.out.println(time.format(formatter2));
LocalDateTime日期和时间组合
LocalDateTime dateTime=LocalDateTime.now();
System.out.println(dateTime.toString());
我们可以format它
LocalDateTime dateTime=LocalDateTime.now();
DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(dateTime.format(formatter3));