localdate怎么date
时间: 2023-11-09 07:57:18 浏览: 40
您可以使用以下方法将LocalDate转换为Date:
方法1: 使用LocalDate的atStartOfDay()方法创建一个LocalDateTime,并将其转换为Instant对象。然后使用Date类的from()方法将Instant对象转换为Date对象。
LocalDate localDate = LocalDate.parse("2019-05-08");
Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
Date date = Date.from(instant);
System.out.println(date); //Wed May 08 00:00:00 IST 2019
方法2: 使用LocalDateTime的of()方法将LocalDate与午夜时间(LocalTime.MIDNIGHT)相结合,创建一个LocalDateTime,并将其转换为Instant对象。然后使用Date类的from()方法将Instant对象转换为Date对象。
LocalDate localDate = LocalDate.parse("2019-05-08");
Instant instant = localDate.atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant();
Date date = Date.from(instant);
System.out.println(date); //Wed May 08 00:00:00 IST 2019
方法3: 使用LocalDate的atTime()方法将该日期与给定的时间相结合,创建一个LocalDateTime,并将其转换为Instant对象。然后使用Date类的from()方法将Instant对象转换为Date对象。
请问还有其他问题吗?