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
1public LocalDateTime convertToLocalDateTimeViaMilisecond(Date dateToConvert) {
2 return Instant.ofEpochMilli(dateToConvert.getTime())
3 .atZone(ZoneId.systemDefault())
4 .toLocalDateTime();
5}
1Date yourDate = new Date(); // this will be your java.util.Date instance to convert
2LocalDate date = yourDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
3