Convert the Current Time to a java.sql.Date Object

Firstly, create a Calendar class object.

Calendar calendar = Calendar.getInstance();

Now, import the following package.

import java.sql.Date;

Using a Date class now and creating an object would belong to the above package. Convert the current time to the java.sql.Date Object.

Date sqlDate = new Date((calendar.getTime()).getTime());

The following is an example.

Example

import java.util.Calendar;
import java.sql.Date;
import java.text.ParseException;
public class Demo {
   public static void main(String[] args) throws ParseException {
      Calendar calendar = Calendar.getInstance();
      // object
      Date sqlDate = new Date((calendar.getTime()).getTime());
      System.out.println(sqlDate);
   }
}

Output

2018-11-19
Updated on: 2026-03-11T22:50:43+05:30

712 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements