Problem with java.util.Calendar

I have a Problem with java.util.Calendar.

It is best expressed by the following short main function:

import java.util.*;

public class CalendarProblem {

public static void main(String[] args) {

// problem also encountered in other Locales

Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"),Locale.US);

cal.set(2004,8,31,0,0,1);

System.out.println(cal.get(Calendar.YEAR))); // 2004

// now the Problem

System.out.println(cal.get(Calendar.MONTH));// 9

System.out.println(cal.get(Calendar.DAY_OF_MONTH));// 1

}

}

Although set to the 31st of August, Calendar produces the 1st of September.

Why is that? Is it a bug, or am I using the class wrongly?

Even calling .clear() before setting the time does not help.

Moreover, setting the time by a java.util.Date leads to the same result.

I executed the code under J2SE 1.3.1 .

I'd appreciate any hints.

[995 byte] By [Monsieur_le_Lud] at [2007-9-30 4:05:06]
# 1
Ok, the question was answered elsewhere,it is that the months in Calendar are 0 based...january = 0, august = 7 etc.So the behaviour is just correct.
Monsieur_le_Lud at 2007-6-29 17:42:01 > top of Java-index,Administration Tools,Sun Connection...