I am working on an Android app.
I get a date String and a time string from a JSON
file.
fecha_reporte = "2017-12-17"
hora_reporte = "23:51:00"
I need to convert both strings into a date variable, then later I will need to make some calculations with it.
This is what I have so far:
String fecha = fecha_reporte + " " + hora_reporte;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd H:m:s");
String dateInString = fecha;
try {
Date date2 = formatter.parse(dateInString);
System.out.println(date2);
System.out.println(formatter.format(date2));
Log.d("DURACION","DURACION REPORTE: calculado: "+date2);
} catch (ParseException e) {
e.printStackTrace();
}
The output is a date, but with this format:
Sun Dec 17 23:51:00 GMT-07:00 2017
I need it with following format: 2017-12-17 23:51:00