File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

add method of Calendar

Dorcas Rebanha

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

Joined: Oct 27, 2005
Posts: 20271

How do you exactly check that nothing happens?

I tried your code with some print statements in between:

The output is just as expected:

How To Ask Questions How To Answer Questions
Dorcas Rebanha

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.

I agree. Here's the link:
subject: add method of Calendar
It's not a secret anymore!