Date – LocalDate

A Date object can be converted to LocalDate via an Instant object. Once we have obtained the Instant object from the given Date object, the solution can apply to it the system default time zone, and call the toLocaleDate() method:

// e.g., 2019-03-01
public static LocalDate dateToLocalDate(Date date) {

return dateToInstant(date).atZone(DEFAULT_TIME_ZONE).toLocalDate();
}

Converting from LocalDate to Date should take into account that LocalDate doesn't contain a time component as Date, so the solution must supply a time component as the start of the day (more details regarding this can be found in the Start and end of a day problem):

// e.g., Fri Mar 01 00:00:00 EET 2019
public static Date localDateToDate(LocalDate localDate) {

return Date.from(localDate.atStartOfDay(
DEFAULT_TIME_ZONE).toInstant());
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset