Java Program to convert java.util.Date to LocalDate


At first set the date with java.util.Date −

java.util.Date date = new Date();

Now, convert the date to LocalDate −

Instant instant = Instant.ofEpochMilli(date.getTime());
System.out.println("LocalDate = "+LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate());

Example

 Live Demo

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      java.util.Date date = new Date();
      System.out.println("Date = "+date);
      Instant instant = Instant.ofEpochMilli(date.getTime());
      System.out.println("LocalDate = "+LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate());
   }
}

Output

Date = Thu Apr 18 23:51:06 IST 2019
LocalDate = 2019-04-18
raja
Published on 23-Apr-2019 16:39:00
Advertisements