DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy");
String date = "16/08/2016";
//convert String to LocalDate
LocalDate localDate = LocalDate.parse(date, formatter);
// Localdate to Date
Date.from(localdate.atStartOfDay(ZoneId.systemDefault()).toInstant())
// LocalDate to Calendar
Calendar calendar = Calendar.getInstance();
calendar.setTime(Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
Date yourDate = new Date(); // this will be your java.util.Date instance to convert
LocalDate date = yourDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
date.toInstant().atZone(ZoneId.systemDefault()).toLocaldate()
public LocalDateTime convertToLocalDateTimeViaMilisecond(Date dateToConvert) {
return Instant.ofEpochMilli(dateToConvert.getTime())
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}
public LocalDateTime convertToLocalDateTimeViaInstant(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}
public LocalDate convertToLocalDateViaInstant(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}