You have an error while converting
new SimpleDateFormat("dd/MM/yyyy").format(t.getFechaEmision())
If done this way:
new SimpleDateFormat(FORMATO INICIAL).format(new SimpleDateFormat(FORMATO DESEADO).parse(FECHA A CONVERTIR)));
Convert date from one format to another in Java.
I give as an example this method that receives the format of input, output and the string with the date to be converted. You can also define a LOCALE
for example:
public static final Locale LOCALE_MX = new Locale("es", "MX");
and this would be the method:
public static String dateFormatter(String inputFormat, String outputFormat, String inputDate){
//Define formato default de entrada.
String input = inputFormat.isEmpty()? "yyyy-MM-dd hh:mm:ss" : inputFormat;
//Define formato default de salida.
String output = outputFormat.isEmpty()? "d 'de' MMMM 'del' yyyy" : outputFormat;
String outputDate = inputDate;
try {
outputDate = new SimpleDateFormat(output, LOCALE_MX).format(new SimpleDateFormat(input, LOCALE_MX).parse(inputDate));
} catch (Exception e) {
System.out.println("dateFormatter(): " + e.getMessage());
}
return outputDate;
}
These are examples of how to use the method, where I define the format that has my original date "MM / dd / yyyy", the format I want to obtain "dd / MM / yyyy" and the date that I want to change format:
System.out.println("FECHA :" + dateFormatter("MM/dd/yyyy","dd/MM/yyyy", "05/03/2017"));
would get:
FECHA: 03/05/2017
another example:
System.out.println("FECHA: " + dateFormatter("yyyy-MM-dd hh:mm:ss","dd/MM/yyyy", "2017-05-03 12:24:34"));
in which you would get the format you want:
FECHA: 03/05/2017
You can even modify the output format:
System.out.println("FECHA: " + dateFormatter("yyyy-MM-dd hh:mm:ss","d 'de' MMMM 'del' yyyy", "2017-05-03 12:24:34"));
and you would get:
FECHA: 3 de mayo del 2017