I have a code that supposedly passes to dd-mm-yyyy
or for example 02-10-2017
but my problem is that this code instead of passing 02-10-2017
is going 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);
}
};
More down to add my database as string