File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes add method of Calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "add method of Calendar" Watch "add method of Calendar" New topic
Author

add method of Calendar

Dorcas Rebanha
Greenhorn

Joined: Apr 04, 2007
Posts: 18
I have this code:

Calendar oneYearLater = new GregorianCalendar();
oneYearLater.add(Calendar.YEAR, 1);

The first line gets today's date. The second line should change the value, but it isn't doing it.

I am running Drools in debug mode, and the value of the field doesn't change from one line to the next. What am I doing wrong?

I have also tried this:

Calendar oneYearLater = new GregorianCalendar(2108, 9, 24);

The result that shows in the debug Variables display area looks pretty random to me. When I look at the values, cdate is null, and gdate has a cachedYear of 2004, while the dayOfMonth, Month and Year are all 0. Again, what am I doing wrong?

Thanks for any help.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

How do you exactly check that nothing happens?

I tried your code with some print statements in between:

The output is just as expected:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dorcas Rebanha
Greenhorn

Joined: Apr 04, 2007
Posts: 18
Verrry innnteresting. Printing the field as you suggested had the same results that you showed, that is, the field changed as it was supposed to.

But the variable display area of the debug mode showed that the field did NOT change.

This tells me that my question is not about making the code work right, but it's really about making the environment work right, so the code will do what it is supposed to do. Or that I need to understand the environment, and how to interpret what debug is telling me. I'll go to the experienced folks around here for that.

Thanks for your help.

Dorcas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: add method of Calendar