I want to convert java.util.Date to java.sql.Date but I want hours, minutes, and seconds as well but java.sql.Date can be used only to store date(no time) . I tried the below code but it is giving only year, month, and day for the java.sql.Date object.
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date parsed = format.parse("20110210120534");
System.out.println(format.parse("20110210120534"));
java.sql.Date sql = new java.sql.Date(parsed.getTime());
System.out.println("SQL date is= "+sql);
Current output:
2011-02-10
Desired output:
2011-02-10 12:05:34
java.sql.Dateprecisely to store only informations about date, not about time (we havejava.sql.Timefor that). What are you really trying to achieve? Why are you want to usejava.sql.Dateinstead ofjava.util.Date?java.sql.Timestampinstead ofjava.sql.Dateif you want more precision.java.util.date.