Java LocalDate to Date

Convert LocalDate to Date in java

In this post, we will see how to convert LocalDate to Date. Java 8 has introduced a lot of new APIs for Date and time.

There can be many ways to convert Java LocalDateTime to date.


Using Instant object

You can convert LocalDate to Date using Instant object which we can from Zone. Here is the code for the same:


Using java.sql.Date

The easiest way to convert LocalDate to Date is to use valueOf() method from java.sql.Date. You should prefer first approach because java.util.Date is meant for database layer and may change the dependency later in further java versions.

Here is complete program to convert between LocalDate to Date.

Output:

Sun Thu Jan 07 00:00:00 IST 2021
=====================
2021-01-07

That’s all about Java LocalDate to Date in Java 8.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *