Tutorialspoint

1 Answer
Samual Sam

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

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.