The error timestamp format should be yyyy-mm-dd hh: mm: ss [.fffffffff], keeping the timestamp in the data file
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss a z");
sdf.setTimeZone(TimeZone.getTimeZone("US/Eastern"));
String DateToStoreInDataBase= sdf.format(obj1.getSomeDate().toGregorianCalendar().getTime());
System.out.println(emprSubDte);
Timestamp ts = Timestamp.valueOf(emprSubDte);
preparedStatement.setTimestamp(72,ts);
sysout DateToStoreInDataBase is = "2014-19-13 12:19:59 PM EDT" when I try to save this result to the database when I get an error. The timestamp format should be yyyy-mm-dd hh: mm: ss [.fffffffff].
I have the same format but still I get the error.
+3
source to share
2 answers
The problem is creating an instance of SimpleDateFormat. You are using this pattern: "yyyy-mm-dd hh: mm: ss a z"
The question is in the month. It should be "MM" instead of "mm". "mm" means "minute per hour".
Link: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
+3
source to share