Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getdate from datepicker android

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.

like image 286
Aymen Taarit Avatar asked Dec 07 '11 00:12

Aymen Taarit


1 Answers

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(); } 
like image 143
Andrés Canavesi Avatar answered Sep 30 '22 04:09

Andrés Canavesi