I'm using a datePicker for an application that will be used in the course, but when I convert it from int to Date, it returns the date 3/29/2018 as follows:
Wed Sep 08 00:00:00 GMT 34
Code that is called the datePicker
@SuppressLint("ValidFragment")
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/Sao_Paulo"));
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
month++;
etDataNascimentoCondutor.setText(day+ "/" + month + "/" + year);
}
}
Converting to date
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String sDataNascimento = etDataNascimentoCondutor.getText().toString();
try {
dataNascimentoCondutor = df.parse(sDataNascimento);
Log.v("Data Capturada", dataNascimentoCondutor.toString());
} catch (ParseException e) {
e.getMessage();
throw new RuntimeException();
}