GregorianCalendar setTime

Can someone explain why this occurs? Date d contains a date of 02/02/2002 -- why did the month increment?!

//test

cal =new java.util.GregorianCalendar(Integer.parseInt("2002"),Integer.parseInt("01"),Integer.parseInt("01"));

// Get the next day

cal.roll(java.util.GregorianCalendar.DATE, 1);

java.util.Date d = cal.getTime();

[568 byte] By [jlemm] at [2007-9-27 1:22:12]
# 1

In Gregorian Calendar, the integers to specify months are zero-based, ie: January = 0.

Try this, it's a little simpler

...

import java.util.*;

int year=2002;

int month=0;

int day=1;

cal = new GregorianCalendar(year, month, day);

...

rwhitect at 2007-7-4 19:09:20 > top of Java-index,Archived Forums,Java Programming...
# 2
In Java's implementation of GregorianCalendar, months are based on 0. 0 is January, 1 is February, 2 is March, etc. Integer.parseInt("01") says you want to use February. The month is not being incremented, it's being set incorrectly in the first place.
jscriptstuff at 2007-7-4 19:09:20 > top of Java-index,Archived Forums,Java Programming...
# 3
Ahhhhhh .... tricky! They snuck that one in on me. Thank you for the responses.
jlemm at 2007-7-4 19:09:20 > top of Java-index,Archived Forums,Java Programming...