Step 1: Let's create a LocalDate object to represent the current date.
LocalDate localDate = LocalDate.now();
Step 2: In order to convert LocalDate to Date, we first need to covert the LocalDate to an Instant class object.
Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
Step 3: Now we can convert the instant object to java.util.Date class object.
Date date = Date.from(instant);
Complete Java Code
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
public class LocalDateToDateExample {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now();
Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
Date date = Date.from(instant);
System.out.println(date);
}
}
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!