Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

After setting calendar returns different date.

 
Russell Sowell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the following code the values are...

year = 2004
month = 11
day = 25
^^ All integers ^^



but my output is...
1
17
2006

Seems like I missed something dealing with the calendar class. Any help is appreciated.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using your own version of GregorianCalendar ? There is no DAY in the standard java.util.GregorianCalendar API.
 
kiran mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


While running the above code, i am getting the results as expected
2004
11
25
Please check the values of the variables year, month, day.
 
Russell Sowell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I corrected the mistake in my sample code above, my code uses .DATE. Looking into my data source. I am taking the data from a file first and splitting the data from a string.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
year = 2004
month = 11
day = 25


Did you call System.out.println on these variables ?
 
Russell Sowell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To test my integers I outputed them with...



They returned...
2004
12
25

But the rest of the output involving the calendar is still the same.
 
Russell Sowell
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that part of my problem is that the Calender class starts counting months at 0. So 12 was actually January, and therefore also moving forward my year.

Still doesn't explain why my output was THAT far off, but its coming together.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic