I take in the date from the html
field as date/month/year
. If the input is :
01/07/2013
the date in the mysql
database goes as 2013-08-01
. Thus the month gets incremented by one. Why is that ?
Following snippet inserts the date to the DB from html field.
String dateMonthYear[] = issueDate.split("/");
System.out.println("DATE MONT YEAR-------> "+dateMonthYear[1]);
// PRINTS THE CORRECT MONTH
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(dateMonthYear[2]));
cal.set(Calendar.MONTH, Integer.parseInt(dateMonthYear[1]));
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateMonthYear[0]));
Date issueDateDB = cal.getTime();
issued.setDateOfIssue(issueDateDB);
// commit operation
The type of the corresponding type in the db
is Date
. What could be the reason that moth gets incremented by one
?