0

im trying to get de date from a a jdatechooser, then convert it to a string, but when I try to do this this.fechaTxt.setText(""); it doesnot let me

        String fecha1 = this.fechaTxt.getDate().toString();

        Viaje viaje = new Viaje();

        viaje.setFecha(fecha1);


        try {
            this.ingresarViaje(viaje);

            this.fechaTxt.setText("");

            JOptionPane.showMessageDialog(null, "Viaje Ingresado");

        } catch (Exception e) {
            System.out.println("ERROR" + e.getMessage());

}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jhondoe
  • 3
  • 2

1 Answers1

1

Start by getting the actual date from the JDateChooser...

Date date = fechaText.getDate();

Then you could use DateFormat or a SimpleDateFormat to format as a String

Just remember, unless you need to display the date for some reason, you really shouldn't convert it to a String, but instead leave it as a Date object

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366