发布于 2个月前

Java把LocalDate转换为Date

有时需要在LocalDate和Date之间互转。

LocalDate转换为Date

LocalDate localDate = LocalDate.now();
System.out.println("LocalDate = " + localDate);
Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
System.out.println("Date      = " + date);

Date转换为LocalDate

localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
System.out.println("LocalDate = " + localDate);
©2020 edoou.com   京ICP备16001874号-3