Im getting 3914-01-06 as an output when the datepicker selected value input is 2014-01-06
int day = view.getDayOfMonth();
int month= view.getMonth();
int year = view.getYear();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formatedDate = sdf.format(new Date(year, month, day));
Log.d("test", "" + formatedDate);//Here i'am retrieving 3914 instead 2014
According to the documentation,
Date()
's first argument is "the year minus 1900". That is why you get 3914 (=2014+1900). As the documentation also states, useCalendar
orGregorianCalendar
instead ofDate
.