problem when determining the date with the jdatechooser

0

I have a jdatechooser in my project and I want the user to choose a date, the problem is that if the user chooses August 2, 2018 when processing it results in September 2, 2020, I do not know how to readjust it

String dias = Integer.toString(fechacita.getCalendar().get(Calendar.DAY_OF_MONTH));
        String mess = Integer.toString(fechacita.getCalendar().get(Calendar.MONTH + 1));
         String anoss = Integer.toString(fechacita.getCalendar().get(Calendar.YEAR));


        fecha = dias + "/" + mess + "/" + anoss;
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
            Date parsedDate = dateFormat.parse(fecha);
            dateFormat.format(parsedDate);
            timestamp = new java.sql.Timestamp(parsedDate.getTime());
        } catch (ParseException ex) {
            Logger.getLogger(ModificarServicio.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Hubo un error, por favor contactar con el proveedor del servicio", "Error", JOptionPane.ERROR_MESSAGE);
        }
    
asked by Efrainrodc 13.08.2018 в 11:40
source

1 answer

0

What happens is that you tell him that the month you select adds him 1 so if he selects August that is month 8 and you add 1 which is month 9, you will have September.

So you must change this:

String mess = Integer.toString(fechacita.getCalendar().get(Calendar.MONTH + 1));

By:

String mess = Integer.toString(fechacita.getCalendar().get(Calendar.MONTH));

The only thing that changes is that I removed the +1 that you have in the mess string.

    
answered by 13.08.2018 в 13:53