convert java date to localdate

java

To convert a java.util.Date object to a java.time.LocalDate object, you can use the toInstant method of the Date class to get an Instant object, and then use the atZone method of the Instant object to get a ZonedDateTime object. Finally, you can use the toLocalDate method of the ZonedDateTime object to get the LocalDate object.

Here is an example:

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class Main {
  public static void main(String[] args) {
    Date date = new Date();
    ZonedDateTime zonedDateTime = date.toInstant().atZone(ZoneId.systemDefault());
    LocalDate localDate = zonedDateTime.toLocalDate();
    System.out.println(localDate);
  }
}

This will convert the Date object to a LocalDate object with the same date and the system default time zone.