How to get the date from the DatePicker widget in Android?

David picture David · Jun 21, 2011 · Viewed 100.1k times · Source

I use a DatePicker widget in Android for the user to set a date, and want to get the date value when a confirm button is clicked, how can I do that?

Answer

Onuray Sahin picture Onuray Sahin · Jun 21, 2011

Try this:

 DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
 int day = datePicker.getDayOfMonth();
 int month = datePicker.getMonth() + 1;
 int year = datePicker.getYear();