T
Tim Slattery
Can anybody explain this behavior?? This code:
GregorianCalendar gc = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("MMMM yyyy");
System.out.println("Current date: " +
gc.get(GregorianCalendar.MONTH) + "/" +
gc.get(GregorianCalendar.DAY_OF_MONTH)
+ "/" + gc.get(GregorianCalendar.YEAR));
System.out.println(sdf.format(gc.getTime()));
gc.add(GregorianCalendar.MONTH, 6);
System.out.println("Six months future date: " +
gc.get(GregorianCalendar.MONTH) + "/" +
gc.get(GregorianCalendar.DAY_OF_MONTH)
+ "/" + gc.get(GregorianCalendar.YEAR));
System.out.println(sdf.format(gc.getTime()));
results in this output:
Current date: 9/24/2005
October 2005
Six months future date: 3/24/2006
April 2006
Why does SimpleDateFormat seem to bump the month up by one??
GregorianCalendar gc = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("MMMM yyyy");
System.out.println("Current date: " +
gc.get(GregorianCalendar.MONTH) + "/" +
gc.get(GregorianCalendar.DAY_OF_MONTH)
+ "/" + gc.get(GregorianCalendar.YEAR));
System.out.println(sdf.format(gc.getTime()));
gc.add(GregorianCalendar.MONTH, 6);
System.out.println("Six months future date: " +
gc.get(GregorianCalendar.MONTH) + "/" +
gc.get(GregorianCalendar.DAY_OF_MONTH)
+ "/" + gc.get(GregorianCalendar.YEAR));
System.out.println(sdf.format(gc.getTime()));
results in this output:
Current date: 9/24/2005
October 2005
Six months future date: 3/24/2006
April 2006
Why does SimpleDateFormat seem to bump the month up by one??