Date怎么转localDate
首先,将java.util.Date对象转换为java.time.Instant对象。Instant是表示时间戳的类,可以精确到纳秒级别。
        Date date = new Date();
        Instant instant = date.toInstant(); 
然后,使用java.time.ZoneId类来指定时区,将Instant对象转换为java.time.LocalDateTime对象。LocalDateTime是表示日期和时间的类,不包含时区信息。
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId); 
最后,从LocalDateTime对象中提取日期部分,得到java.time.LocalDate对象。
LocalDate localDate = localDateTime.toLocalDate(); 
最后得到:

localDate转Date
使用atStartOfDay()方法将LocalDate转换为LocalDateTime,然后使用ZoneId.systemDefault()获取系统默认的时区,最后使用toInstant()将LocalDateTime转换为Instant对象。
最后,我们使用Date.from()方法将Instant对象转换为Date对象,即完成了LocalDate到Date的转换。
Instant instant1 = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
        Date date = Date.from(instant1); 
最后得到:




















