0
I have a code that supposedly goes to format dd-mm-yyyy
or for example 02-10-2017
but my problem is that this code instead of passing to 02-10-2017
is passing to 2-10-2017
.
Code :
dt = 2 + "-" + 10 + "-" + 2017;
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
try {
sdf.parse(dt);
date_text.setText(dt);
Log.d(tag,""+dt);
} catch (ParseException e) {
e.printStackTrace();
}
In the log I have this result :
07-13 20:42:25.914 12020-12020/com.pedrogouveia.averagemaker D/tag: 2-10-2017
Updated code :
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
month = month + 1;
date_button.setVisibility(View.GONE);
date_text = (TextView) rootView.findViewById(R.id.date_text);
date_text.setVisibility(View.VISIBLE);
dt = day + "-" + month + "-" + year;
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
dataInterpetrada = sdf.format(dt); <---------Esta linha esta vermelha e esta dizendo incompatible types java.util.dates and java.lang.string
dt = sdf.format(dataInterpetrada);
date_text.setText(dt);
}
};
Further down add dt to my database as string
Strange, you wrote it
dt = 2 + "-" + 10 + "-" + 2017;
, but the log saysD/tag: 14-7-2017
, did you make any confusion?– Guilherme Nascimento
It was not just an example the 2-10-2017 mine has a dataPicker
– Pedro Gouveia