1public static Calendar toCalendar(Date date){
2 Calendar cal = Calendar.getInstance();
3 cal.setTime(date);
4 return cal;
5}
1package com.mkyong.date;
2
3import java.time.LocalDate;
4
5public class JavaDateExample1 {
6
7 public static void main(String[] args) {
8
9 String date = "2016-08-16";
10
11 //default, ISO_LOCAL_DATE
12 LocalDate localDate = LocalDate.parse(date);
13
14 System.out.println(localDate);
15
16 }
17}
18Copy
1// Localdate to Date
2Date.from(localdate.atStartOfDay(ZoneId.systemDefault()).toInstant())
1
2 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy");
3 String date = "16/08/2016";
4
5 //convert String to LocalDate
6 LocalDate localDate = LocalDate.parse(date, formatter);
7
1dateToConvert.toInstant()
2 .atZone(ZoneId.systemDefault())
3 .toLocalDate();
1public LocalDateTime convertToLocalDateTimeViaInstant(Date dateToConvert) {
2 return dateToConvert.toInstant()
3 .atZone(ZoneId.systemDefault())
4 .toLocalDateTime();
5}