@Test public void dateTest(){ Date now = new Date(); System.out.println(now); // java.util.Date -> java.time.LocalDate LocalDate localDate=now.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); // java.time.LocalDate -> java.sql.Date Date newDate=java.sql.Date.valueOf(localDate); System.out.println(newDate); localDate = localDate.plusDays(1); Date tomorrowDate=java.sql.Date.valueOf(localDate); System.out.println(tomorrowDate); System.out.printf("%1$tF %1$tT ", newDate); }
打印结果: