Prevent JDateChooser from recalculating the date

0

The JDateChooser class when it receives an erroneous date tries to correct it, how can I avoid this behavior?

JDateChooser jDateChooserFecha=new JDateChooser();    
SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");
jDateChooserFecha.setDate(formatoFecha.parse("30/02/2016"));

If I execute the previous code, the value stored in jDateChooserDate is "03/02/2016"

    
asked by Javier 28.11.2016 в 17:15
source

1 answer

0

JDateChooser detects the year 2016 as not leap year, February only has 28 days , when assigning with day 30 , the final result would be on March 2 > (02/03) , I think the result is correct.

One option would be to use the Calendar class to also have account for leap years.

Calendar c = Calendar.getInstance();
c.set(2016, Calendar.FEBRUARY, 28);
JDateChooser jDateChooserFecha=new JDateChooser(c.getTime());
    
answered by 28.11.2016 в 19:11