Hi i am trying to parse a string into a java.sql.date
Here is what i am doing
private static SimpleDateFormat sdfout = new SimpleDateFormat("yyyy.MM.dd.HH.mm");
try{
String date = "2010.09.30.13.18";
task.setDueDate(new java.sql.Date(sdfout.parse(date).getTime()));
}
The problem is that i only get the date back. Not the time.
Am i doing this correctly
The code logic is fine, you only need
java.sql.Timestampinstead ofjava.sql.Date. The SQL timestamp represents both the date and time parts, like date in Java. The SQL date represents only the date part.See also:
Noted should be that you should prefer
java.util.Dateoverjava.sql.Timestampin the model objects and use theTimestamponly at the very moment when you’re about to set it in a SQL query. This separates the model objects from the JDBC API and improves their portability and reusability.