aspose file tools*
The moose likes Beginning Java and the fly likes After setting calendar returns different date. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "After setting calendar returns different date." Watch "After setting calendar returns different date." New topic
Author

After setting calendar returns different date.

Russell Sowell
Greenhorn

Joined: Mar 12, 2009
Posts: 4
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Are you using your own version of GregorianCalendar ? There is no DAY in the standard java.util.GregorianCalendar API.


[My Blog]
All roads lead to JavaRanch
kiran mathew
Greenhorn

Joined: Jun 16, 2008
Posts: 16


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

Joined: Mar 12, 2009
Posts: 4
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

year = 2004
month = 11
day = 25


Did you call System.out.println on these variables ?
Russell Sowell
Greenhorn

Joined: Mar 12, 2009
Posts: 4
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

Joined: Mar 12, 2009
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: After setting calendar returns different date.