I have a field that is of type String
, where a data
is entered in the format dd/MM/yyyy
, I'm converting to java.sql.Date
, the result is: 2018-01-01.
What I needed was to get the date in the format: dd/MM/yyyy
, which would be: 01/01/2018, but needs to be in data
format, not String
, is it possible?
The method I use is this (I've actually simplified it to make it easier for those who can help by running the code):
public class NewClass {
public static void main(String[] args) throws ParseException {
String dataInicialString = "01/01/2018";
String dataFinalString = "14/05/2018";
DateFormat fmt = new SimpleDateFormat("dd/MM/yyyy");
java.sql.Date dataInicial = null;
java.sql.Date dataFinal = null;
dataInicial = new java.sql.Date(fmt.parse(dataInicialString).getTime());
dataFinal = new java.sql.Date(fmt.parse(dataFinalString).getTime());
System.out.println("DATAINICIAL:" + dataInicial);
System.out.println("DATAFINAL:" + dataFinal);
}
}