Java Convert LocalDate to SQL Date
Tags: Java LocalDate Java SQL Date Java 8
In this Java core tutorial we learn how to convert a java.time.LocalDate object to a java.sql.Date object in Java programming language.
How to convert LocalDate to SQL Date in Java
In Java, with a given LocalDate object we can use the java.sql.Date.valueOf(LocalDate date) static method to instantiate a new SQL Date object from LocalDate value as the following Java program.
ConvertLocalDateToSQLDateExample1.java
import java.sql.Date;
import java.time.LocalDate;
public class ConvertLocalDateToSQLDateExample1 {
public static void main(String... args) {
LocalDate localDate = LocalDate.now();
// Convert LocalDate object to SQL Date object
Date date = Date.valueOf(localDate);
System.out.println("LocalDate: " + localDate);
System.out.println("Date: " + date);
}
}
LocalDate: 2022-05-23
Date: 2022-05-23
Happy Coding 😊
Related Articles
Java Convert Instant to SQL Date
Java Convert LocalDateTime to SQL Date
Java Convert ZonedDateTime to SQL Date
Java Convert OffsetDateTime to SQL Date
Java Convert Calendar to SQL Date
Java Convert GregorianCalendar to SQL Date
Java Convert SQL Date to LocalDate
Java Convert SQL Date to LocalDateTime
Java Convert SQL Date to ZonedDateTime
Java Convert SQL Date to OffsetDateTime
Java Convert SQL Date to Calendar