DatePicker Date Return Issues

0

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();
}
    
asked by anonymous 29.03.2018 / 17:37

1 answer

0
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");//variavel na classe    
Calendar calendar; //variavel na classe

/////////////////////

@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
    calendar = Calendar.getInstance(); //faça variavel calendar na classe
    calendar.set(year,month,day);
    Date date = calendar.getTime();//metodo getTime converte o Calendar para Date
    etDataNascimentoCondutor.setText(df.format(date));
}
    
29.03.2018 / 20:38