LocalDateTime ltd = LocalDateTime.now();
LocalDate ltd1 = LocalDate.now();
LocalTime ltd2 = LocalTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
String format = dateTimeFormatter.format(ltd);
LocalDateTime localDateTime = ltd.plusDays(1);
String format1 = dateTimeFormatter.format(localDateTime);
System.out.println("格式化前 "+ltd);
System.out.println("格式化后 "+format);
System.out.println("一天后 "+localDateTime);
System.out.println("格式化后一天后 "+format1);
System.out.println(ltd1);
System.out.println(ltd2);
System.out.println("年"+ltd.getYear());
System.out.println("月"+ltd.getMonth());
System.out.println("月"+ltd.getMonthValue());
System.out.println("日"+ltd.getDayOfMonth());
System.out.println("时"+ltd.getHour());
System.out.println("分"+ltd.getMinute());
System.out.println("分"+ltd.getSecond());
打印结果:
格式化前 2022-04-15T13:03:52.986
格式化后 2022-04-15 01:03:52
一天后 2022-04-16T13:03:52.986
格式化后一天后 2022-04-16 01:03:52
2022-04-15
13:03:52.986
年2022
月APRIL
月4
日15
时13
分3
分52