Home > Java > javaTutorial > How to Convert a java.util.Date to a java.sql.Date?

How to Convert a java.util.Date to a java.sql.Date?

Barbara Streisand
Release: 2024-12-20 19:59:10
Original
691 people have browsed it

How to Convert a java.util.Date to a java.sql.Date?

Convert from java.util.Date Object to a java.sql.Date Object

Query:
How to convert java.util.Date to java.sql.Date?

Problem Statement:
When using java.util.Date as input and creating a query from it, a java.sql.Date is required. The conversion cannot be done explicitly or implicitly.

Solution:

public class MainClass {

 public static void main(String[] args) {
   java.util.Date utilDate = new java.util.Date();
   java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
   System.out.println("utilDate:" + utilDate);
   System.out.println("sqlDate:" + sqlDate);

 }

}
Copy after login

The above is the detailed content of How to Convert a java.util.Date to a java.sql.Date?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template