2
I got a field that’s like String
, where a data
in 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 format data
, nay String
, it is possible?
The method I use is this( ):
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);
}
}
Another duplicate: Change format of a date from yyyy-MM-dd to dd-mm-yyyy
– user28595
To format, you need to transform into a string, in sql format. Date or Ulti.Date you will not get this format.
– user28595