Java Program to convert LocalDate to java.util.Date

Java 8Object Oriented ProgrammingProgramming

Let us first set the LocalDate to current date −

LocalDate date = LocalDate.now();

Create an Instant −

Instant i = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();

Convert it to java.util.Date −

java.util.Date.from(i)

Example

 Live Demo

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
public class Demo {
   public static void main(String[] args) {
      LocalDate date = LocalDate.now();
      System.out.println("LocalDate = "+date);
      Instant i = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
      System.out.println("java.util.Date = "+java.util.Date.from(i));
   }
}

Output

LocalDate = 2019-04-19
java.util.Date = Fri Apr 19 00:00:00 IST 2019
raja
Published on 23-Apr-2019 08:51:40
Advertisements