[英]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. 我想使用两个JCalendar,一个使用Calendar.getInstance()接收实际日期,其他日期与日期相同但比第一个日期长一个月。 for example:
例如:
Jcalendar1 = 05/04/2014 Jcalendar2 = 05/05/2014 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? 但是将jCalendar2设置为05/03/0001这是jcalendar中的错误吗?
How can I make that? 我该怎么做? help please
请帮助
PD: sorry for my English PD:对不起我的英语
According to the Calendar javadoc for set(int,int,int) you'd set 17 Jan 2014 with 根据用于set(int,int,int)的Calendar javadoc ,您将设置2014年1月17日
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. Calendar.YEAR
, Calendar.MONTH
, Calendar.DAY_OF_MONTH
是您可以在日历中处理的字段的名称,而不是当前日期的实际值或占位符。
Edit, after your comment - January is month 0, sorry for the typo. 编辑,在您的评论后 - 1月是0月,抱歉打字错误。
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. 你想在这样的情况下查找java文档或者谷歌的例子。
cal.set( Calendar.YEAR, 2014 )
cal.set( Calendar.MONTH, 5 )
and so on 等等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.