I want to get date from datepicker widget in android I have tried with this
Date date1= (Date) new Date
(dpBirthDate.getYear(), dpBirthDate.getMonth(), dpBirthDate.getDayOfMonth());
date1 = (Date) new SimpleDateFormat("yyyy-MM-dd").parse(date1.toString());
But I get a date like this mon 7 dec 2011 time
... and all I want to get is the yyyy-MM-dd
format to store it in the database.
I tried also to concat the year-month-day like this but the problem is for example today 2011-12-7 the day should be 07 to be valid
Could you help me please.
I use this:
/**
*
* @param datePicker
* @return a java.util.Date
*/
public static java.util.Date getDateFromDatePicker(DatePicker datePicker){
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth();
int year = datePicker.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
return calendar.getTime();
}