Formatting date to save

Asked

Viewed 22 times

0

Hello, I need to convert a date that is in String to save to a variable data_inicio of the kind Date in Mysql and I did it as follows:

String data = "14/11/2017";
        SimpleDateFormat formataData = new SimpleDateFormat("dd/MM/yyyy");
        Date dataEntrada = null;
        try {
           // dataEntrada = formataData.parse("21/09/2010");
            dataEntrada = formataData.parse(data);
            System.out.println("data entrada -> "+dataEntrada);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }

Resuldado generated by dateEntrada = Tue Nov 14 00:00:00 BRST 2017 but I need this dateEntrada to be in 2017/11/14 format to save to Mysql database

  • Hi Fabrício. Maybe I didn’t understand your question, but after you converted the String to a Date it would not be possible to do the insert bank using converted date? I don’t know what you’re using (PreparedStatement JdbcTemplate, etc) but in general it is quite easy to use the type Date. It seems pretty strange to do parse to then make a format.

  • Cara has some 3 or 4 questions about how to change date format to bank form or Brazilian format. I suggest you stop and read a little better the answers you received, because in all of them the doubt has been solved.

  • Dude thanks now worked out, I’m a little confused because the code returned a String and I thought I should send a Date to the database. Now I get it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.