I have the following program but it wrongly displays the month. please help.
date1="31/12/2011";
SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
try {
d1 = (Date)formatter.parse(date1);
System.out.println("dateeeeeeeeeeeeeeee " + date1);
tdy1=Calendar.getInstance();
System.out.println("tdy mnthhhhhhhhhhh " + tdy1.get(Calendar.MONTH));
tdy1.setTime(d1);
System.out.println("Month of date1= " + tdy1.get(Calendar.MONTH));
//catch exception
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
And out put is :
Month of date1= 0
Wat might be the problem??
Try below code
Note”
Calendar.MONTH is return integer value and it is start from 0 to 11 means 0=JANUARY and 11=DECEMBER
for more detail check Calendar