Jhondoe
Jhondoe

Reputation: 3

Jdatechooser content

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

}

Upvotes: 0

Views: 126

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347332

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

Upvotes: 1

Related Questions