How to Convert java.sql.Date to java.util.Date in Java? Last Updated : 04 Sep, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report If we have the Date object of the SQL package, then we can easily convert it into an util Date object. We need to pass the getTime() method while creating the util Date object. java.util.Date utilDate = new java.util.Date(sqlDate.getTime()); It will give us util Date object. getTime() method Syntax: public long getTime() Parameters: The function does not accept any parameter. Return Value: It returns the number of milliseconds since January 1, 1970, 00:00:00 GTM. Exception: The function does not throw any exception. Java // Java program to Convert java.sql.Date to java.util.Date import java.sql.*; import java.text.*; import java.util.*; public class GFG { public static void main(String[] args) { // sql date object takes time in milliseconds long millis = System.currentTimeMillis(); // creating sql date object java.sql.Date sqlDate = new java.sql.Date(millis); // creating util date object by passing gettime() // method of sql date class java.util.Date utilDate = new java.util.Date(sqlDate.getTime()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // converting the util date into string format final String stringDate = dateFormat.format(utilDate); // printing both dates System.out.println("utilDate:" + stringDate); System.out.println("sqlDate:" + sqlDate); } } Output: utilDate:2021-01-20 sqlDate:2021-01-20 Comment More infoAdvertise with us Next Article How to Convert java.sql.Date to java.util.Date in Java? K kapilnama1998 Follow Improve Article Tags : Java Java Programs Java-Date-Time Practice Tags : Java Similar Reads How to Convert java.util.Date to java.sql.Date in Java? Date class is present in both java.util package and java.sql package. Though the name of the class is the same for both packages, their utilities are different. Date class of java.util package is required when data is required in a java application to do any computation or for other various things, 3 min read How to convert Date to String in Java Given a date, the task is to write a Java program to convert the given date into a string. Examples: Input: date = "2020-07-27" Output: 2020-07-27 Input: date = "2018-02-17" Output: 2018-02-17 Method 1: Using DateFormat.format() method Approach: Get the date to be converted.Create an instance of Sim 3 min read How to Convert a String to a LocalDate in Java? Converting a String to a LocalDate in Java is a common operation when you are dealing with date inputs from users. Java provides the LocalDate class in the java.time package for representing a date without time information. LocalDate class is part of the java.time package introduced in Java 8. Strin 2 min read How to Create a Date Object using the Calendar Class in Java In Java, the Calendar class can provide a flexible way to handle the dates and times. This article demonstrates how to create the Date object using the Calendar class by setting the specific date and time and converting it to the Date object and printing the exact date and time. This approach offers 2 min read Java Program to Convert Date to String The date type object can be converted to a string in Java using a large variety of in-built classes available in Java. Given a date, we need to convert the date to a given format of the string. Examples: Input: date = â2020-11-13âOutput: 2020-11-13 Input: date = â2020-12-14âOutput: 2020-12-14 Method 3 min read Like