Zero Based calendar ???

B

Benjamin Stewart

Hello!
We are having what we perceive to be an error in the Gregorian calendar.
Running the following code;

/*
* blah.java
*
* Created on 30 June 2003, 11:52
*/

package source.com;

/**
*
* @author bstewart
*/
public class blah {

/** Creates a new instance of blah */
public blah() {
java.util.GregorianCalendar oCal = new
java.util.GregorianCalendar();
System.out.println(oCal.get(oCal.MONTH));

}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
blah oblah = new blah();
}

}


If the current month is 6 but this function returns 5. We are finding
that everything is offset by 1. Now we assume that the arrays for this
object are zero based, am I supposed to treat our calendar as zero based
as well ?? Is this a bug or a feature ??

Ben
 
P

Paul Tomblin

In a previous article said:
If the current month is 6 but this function returns 5. We are finding
that everything is offset by 1. Now we assume that the arrays for this
object are zero based, am I supposed to treat our calendar as zero based
as well ?? Is this a bug or a feature ??

Did you try reading the documentation?

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html

MONTH

public static final int MONTH

Field number for get and set indicating the month. This is a
calendar-specific value. The first month of the year is JANUARY which is
0; the last depends on the number of months in a year.
 
M

Michiel Konstapel

Is this a bug or a feature ??

The jury is still out on that one...
Michiel
 
P

pete kirkham

Benjamin said:
Hello!
We are having what we perceive to be an error in the Gregorian calendar.
Running the following code;

/*
* blah.java
*
* Created on 30 June 2003, 11:52
*/

package source.com;

/**
*
* @author bstewart
*/
public class blah {

/** Creates a new instance of blah */
public blah() {
java.util.GregorianCalendar oCal = new
java.util.GregorianCalendar();
System.out.println(oCal.get(oCal.MONTH));

}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
blah oblah = new blah();
}

}


If the current month is 6 but this function returns 5. We are finding
that everything is offset by 1. Now we assume that the arrays for this
object are zero based, am I supposed to treat our calendar as zero based
as well ?? Is this a bug or a feature ??

Ben

It's the tradition that you use the value returned by a function for
month or weekday as an index into a zero-based array of names.


Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top