Problem picking screen date

-1

I have a small error getting the date of a jtextfield, the error occurs:

  

String can not be converted to date

Follow my code:

public TelaControle getVendaFromTela() throws ParseException {

    Venda vDaTela = new Venda();

    vDaTela.setCliente(inpCliente.getText());
    vDaTela.setCarro(inpCarro.getText());
    vDaTela.setData(inpData.getText());

    return vDaTela;
    }
    
asked by anonymous 15.04.2017 / 17:57

1 answer

2

If the problem is to convert date to string to type Date, the starting code was going in the right way:

public TelaControle getVendaFromTela() throws ParseException {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

    Venda vDaTela = new Venda();

    vDaTela.setCliente(inpCliente.getText());
    vDaTela.setCarro(inpCarro.getText());
    vDaTela.setData(sdf.parse(inpData.getText()));

    return vDaTela;
}

But to convert from string to Date the correct method is parse , format does the reverse.

    
15.04.2017 / 18:26