简体   繁体   中英

How set JCalendar with a specific date?

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

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM