package org.kodejava.jdbc;
import java.util.Date;
public class UtilDateToSqlDate {
public static void main(String[] args) {
// Create a new instance of java.util.Date
Date date = new Date();
// To covert java.util.Date to java.sql.Date we need to
// create an instance of java.sql.Date and pass the long
// value of java.util.Date as the parameter.
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
System.out.println("Date = " + date);
System.out.println("SqlDate = " + sqlDate);
}
}
The result of the code snippet above:
Date = Sat Oct 09 20:23:27 CST 2021
SqlDate = 2021-10-09
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024