I have a DatePicker
and a TimePicker
in my app. Can anyone tell me how to get the values of the date and time that are selected??? What i mean to say is, for EditText
we can declare as
final EditText name = (EditText) this.findViewById(R.id.nametext);
and we can cast the data of it by using name.getText().toString()
.
So similarly how can we get the values of DatePicker and TimePicker to a String???
DatePicker has
getYear()
getMonth()
getDayOfMonth()
to make a Date object from a DatePicker you'd do new Date(datePicker.getYear() - 1900, datePicker.getMonth(), datePicker.getDayOfMonth());
Note that this constructor was deprecated in API level 1 - please refer to andrescanavesi's answer for a more appropriate way of creating a Date object.
TimePicker has
getCurrentHour()
getCurrentMinute()