import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; public class TestMain { public static void main(String[] args) { LocalDate localDate = LocalDate.now();//.with(TemporalAdjusters.next(DayOfWeek.FRIDAY)); // 格式化LocalDate或LocalTime DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); System.out.println(localDate.format(formatter)); // LocalDate转Date System.out.println(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); LocalDateTime localTime = LocalDateTime.now(); // LocalDateTime转Date System.out.println(Date.from(localTime.atZone(ZoneId.systemDefault()).toInstant())); } }