I am using datepicker to allow the user to pick his date of birth and onDateSet() method i am calculating his age. I have read lot of people recommending this but it is giving wrong answer.
Here is my code
class DOBDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// TODO Auto-generated method stub
// Use the current date as the default date in the picker
return new DatePickerDialog(BookingFormActivity.this, this, dobYear, dobMonth, dobDay );
}
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
// Do something with the date chosen by the user
calOne = Calendar.getInstance();
calTwo = Calendar.getInstance();
calOne.set(Calendar.YEAR,Calendar.MONTH, Calendar.DAY_OF_MONTH);
calTwo.set(year, monthOfYear, dayOfMonth);
long milliseconds1 = calOne.getTimeInMillis();
long milliseconds2 = calTwo.getTimeInMillis();
long diff = milliseconds2 - milliseconds1;
long sec = diff / 1000 ;
long minutes = sec / 60 ;
long hr = minutes / 60 ;
long days = hr / 24 ;
long diffYears = days / 365 ;
//long diffYears = (diff / (24 * 60 * 60 * 1000 * 356));
Log.d("date", String.valueOf(diffYears));
dobYear = year;
dobMonth = monthOfYear;
dobDay = dayOfMonth;
updateDOBDateDisplay();
}
}
what am i doing wrong