Connecting Tech Pros Worldwide Forums | Help | Site Map

Calendar class question

Z.K
Guest
 
Posts: n/a
#1: Jul 17 '07
I was wondering if someone could explain something that while not a big
deal, I would not mind understanding why. When I set the Month field
with the set command with the value 1 and then use get to read it back,
it reads it as 0 and not 1.

Z.K.

John W. Kennedy
Guest
 
Posts: n/a
#2: Jul 17 '07

re: Calendar class question


Z.K wrote:
Quote:
I was wondering if someone could explain something that while not a big
deal, I would not mind understanding why. When I set the Month field
with the set command with the value 1 and then use get to read it back,
it reads it as 0 and not 1.
This should not be. Please provide a complete example of what you are doing.

--
John W. Kennedy
"The first effect of not believing in God is to believe in anything...."
-- Emile Cammaerts, "The Laughing Prophet"
Z.K
Guest
 
Posts: n/a
#3: Jul 20 '07

re: Calendar class question


John W. Kennedy wrote:
Quote:
Z.K wrote:
Quote:
>I was wondering if someone could explain something that while not a
>big deal, I would not mind understanding why. When I set the Month
>field with the set command with the value 1 and then use get to read
>it back, it reads it as 0 and not 1.
>
This should not be. Please provide a complete example of what you are
doing.
>
This is the code. I enter a 2 for month and I get 1 using the get command.

Z.K.

-------------

GregorianCalendar d = new GregorianCalendar();

d.set(Calendar.DAY_OF_MONTH,1);
d.set(Calendar.MONTH,2);
d.set(Calendar.YEAR,2004);
d.set(Calendar.DAY_OF_YEAR,32);

System.out.printf("%d-%d-%d\nDayOfYear =
%d\n",d.get(Calendar.MONTH),d.get(Calendar.DAY_OF_ MONTH),d.get(Calendar.YEAR),d.get(Calendar.DAY_OF_ YEAR));
Robert Larsen
Guest
 
Posts: n/a
#4: Jul 23 '07

re: Calendar class question


Z.K wrote:
Quote:
GregorianCalendar d = new GregorianCalendar();
>
d.set(Calendar.DAY_OF_MONTH,1);
d.set(Calendar.MONTH,2);
d.set(Calendar.YEAR,2004);
d.set(Calendar.DAY_OF_YEAR,32);
>
Last I checked day 32 of the year was in february so Java does nothing
wrong.
Closed Thread