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
Dateit would not be possible to do theinsertbank using converted date? I don’t know what you’re using (PreparedStatementJdbcTemplate, etc) but in general it is quite easy to use the typeDate. It seems pretty strange to doparseto then make aformat.– Anthony Accioly
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.
– user28595
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.
– fabricio b.