import java.time.*;
Dmitry, [25.09.20 14:12]
public LocalDate convertToLocalDate(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}
Dmitry, [25.09.20 14:14]
public Date convertToDate(LocalDate dateToConvert) {
return java.util.Date.from(dateToConvert.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
}
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
LocalDate startDate = LocalDate.parse("28.01.2009", formatter);
LocalDate endDate = LocalDate.parse("05.03.2013", formatter);
Period period = Period.between(startDate, endDate);
System.out.println(period.getYears()); // 4
System.out.println(period.getMonths()); // 1
System.out.println(period.getDays()); // 5