Reputation: 591
I have written following program to convert date string to sql date object to store in db2 but the ouput shown is 2013-01-02 instead of 2013-02-02. can anyone explain why??
String string = "02/02/2013";
Date date = null;
try {
date = new SimpleDateFormat("dd/mm/yyyy", Locale.ENGLISH).parse(string);
java.sql.Date newDate=new java.sql.Date(date.getTime());
System.out.println(newDate);
} catch (ParseException e) {
e.printStackTrace();
}
Upvotes: 0
Views: 138
Reputation: 46428
your format should be
"dd/MM/yyyy"
note that mm
is for minutes whereas MM
is for Month
Upvotes: 1
Reputation: 213281
For month you should use MM
instead of mm
. mm
is used for minutes in hour
: -
date = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH)
Upvotes: 2