ca1.get(Calendar.MONTH + 1)
Calendar.MONTH is an int constant signifying "month", so MONTH+1 is another int constant signifying (I don't know what), so it get's the wrong field. You need
(ca1.get(Calendar.MONTH) + 1)
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
That's odd - please post the relevant code in its latest version
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
You put the brackets in the wrong place
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Look at the suggestion I coded and look at your code. Think about it. I'm here to help you learn to be a Java master, not to do it for you :-)
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
I just copied and ran your original code (with the latest change to the MONTH line) and it works here.
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Here's a simplified version of your code that shows adding days to today's date and printing them out...
public static void main(String[] args) {
Calendar ca1 = Calendar.getInstance();
int nights = 8;
ca1.add(Calendar.DATE, nights);
System.out.println((ca1.get(Calendar.DATE))
+ "/"
+ (ca1.get(Calendar.MONTH) + 1)
+ "/"
+ ca1.get(Calendar.YEAR));
}
Run that, confirm it works, then put the rest of your code back into it until you find out where it breaks.
ps I have to go out in 5 minutes from now...
JamesCherrill
Posting Genius
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073