1

I want to use two JCalendar, one receive actual date with Calendar.getInstance() and other with the same date but with one month over the first. for example:

Jcalendar1 = 05/04/2014 Jcalendar2 = 05/05/2014

I dindn't get how make this, I tryed whit this way...

    Calendar cal = Calendar.getInstance();        
    cal.set(Calendar.YEAR, Calendar.MONTH+1, Calendar.DAY_OF_MONTH);

but set the JCalendar2 with 05/03/0001 it's a error in jcalendar?

How can I make that? help please

PD: sorry for my English

2 Answers2

2

According to the Calendar javadoc for set(int,int,int) you'd set 17 Jan 2014 with

cal.set(2014, 0, 17);

Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH are names of fields that you can address in calendar, not actual values or placeholder for the current date.

Edit, after your comment - January is month 0, sorry for the typo.

Also, if you want the calendar to be "next month", set it to today, then add a month

cal.add(Calendar.MONTH, 1);
Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • thanks for answered, ok now I understand because the calendar set in a other date, but I want to set the second calendar with the next month since today, that is to say the first jcalendar with the date now and the second with the date now but with the second month, if is january the second jcalendar should be February. – user3207976 Jan 17 '14 at 22:07
  • with cal.add(Calendar.MONTH, 1); you solved my problem, thanks a lot :D – user3207976 Jan 18 '14 at 20:13
1

You want to look up the java docs in cases like this or maybe google for examples.

Caledar set method

cal.set( Calendar.YEAR, 2014 )
cal.set( Calendar.MONTH, 5 )

and so on

Robert Beltran
  • 495
  • 3
  • 9
  • thanks for answered, but how can I do if I can set the second jcalendar with the next month?, for example the first jcalendar receive the date now, and the second jcalendar the date now but with the next month, all obtain for the system date, not modify for internal code. – user3207976 Jan 17 '14 at 22:11
  • I'd use a variable and do a +1 or you might use calendar.roll() like so http://www.tutorialspoint.com/java/util/calendar_roll.htm – Robert Beltran Jan 18 '14 at 22:33