El diálogo Datepicker no coincide con la fecha seleccionada

Consulte la siguiente imagen:

Introduzca aquí la descripción de la imagen

El texto arriba dice Thu, Oct 28, 1909 … mientras que el datepicker realmente tiene el valor 3 de enero de 1902. ¿Cuál es el error?

Aquí está mi código:

@SuppressWarnings("deprecation") public void setTheDate(View v){ showDialog(DATE_DIALOG_ID); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: // set date picker as current date return new DatePickerDialog(this, datePickerListener, year, month,day); } return null; } private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() { // when dialog box is closed, below method will be called. public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) { year = selectedYear; month = selectedMonth; day = selectedDay; System.out.println("date" + year + month + day); } }; 

DATE_DIALOG_ID es una constante final, y llamo el método setTheDate () al hacer clic en un botón.

¿Qué estoy haciendo mal?

Simplemente intente esto, similar a su código solamente, pero está funcionando para mí.

 Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); y = c.get(Calendar.YEAR); m = c.get(Calendar.MONTH); dy = c.get(Calendar.DAY_OF_MONTH); DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Log.d("err", "onselect"); mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; } }; DatePickerDialog d = new DatePickerDialog(getActivity(), mDateSetListener, mYear, mMonth, mDay); d.show(); 

Puede utilizar este código para recuperar el valor del selector de fechas. Agregue este código dentro del onDateSet() method of OnDateSetListener()

  TimestampField field = (TimestampField) fieldpicker; Timestamp timestamp = field.getTimestamp(); timestamp.setYear(year - 1900); timestamp.setMonth(monthOfYear); timestamp.setDate(dayOfMonth); field.setTimestamp(timestamp); 

Esto mostrará la fecha en el formato correcto

  • autoclose DatePickerDialog
  • Cuando se utiliza datepicker en android 4.0 y superior .. cómo evitar la vista calendario
  • Establece los límites de fechas de datepicker de android
  • Fecha y hora Validación en android usando edittext oyente
  • Dos selectores de fechas en la misma actividad Android
  • Cómo hacer un DatePicker con DialogFragment y FragmentManager?
  • Fecha máxima en un DatePickerDialog de Android
  • DatePicker con un fondo
  • Vista del calendario de Android de DatePicker
  • Android - OnDateChangedListener - ¿cómo se establece esto?
  • Test DatePickerDialog con robolectric
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.