SimpleDateFormat producing wrong date time when parsing "YYYY-MM-dd HH:mm"
YYYY should be yyyy-
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH);
Please check the documentation for SimpleDateFormat here
Java 6 : http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
Java 7 : http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
Use small case Y, not caps. ie yyyy not YYYY
Check the comments here: Java Simple Date Format and other answers referenced there.
There are two problem.
- Format string should be
"yyyy-MM-dd HH:mm"
. - Datatype to store the time is
TimeStamp
and notDate
in database.
Correct both the things and you will be able to store and retrieve Date with time.