I managed to solve my problem
The following code gives
1.Day of week based on birthdate of the coming birthday
2.Also tested with leap year Feb 29, works perfect
int checkFutureLeapYear=0;
Calendar today=Calendar.getInstance();
Calendar BDay=Calendar.getInstance();
int CYear=today.get(Calendar.YEAR);
// checking whether entered date contains Feb 29 ,if yes check whether //current year is leap years so that it can handle 29
if (Integer.parseInt(m)==02 && (Integer.parseInt(d)==29)) {
// if leap year leave the date as it as , since it can handle 29
if ((CYear % 4 == 0 && CYear % 100 != 0) || (CYear % 400 == 0)) {
d=d;
}
// if not subtract 1 from date , to make it 28 , as current year donot contains feb 29 ,so making it feb 28
else {
int date=Integer.parseInt(d);
date=(date-1);
d=Integer.toString(date);
}
}
String startDate=y+"/"+m+"/"+d;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
Date date=null;
try{
date=sdf.parse(startDate);
}
catch (Exception e) {
e.printStackTrace();
}
BDay.setTime(date);
int BMonth=BDay.get(Calendar.MONTH);
int BDate=BDay.get(Calendar.DATE);
int CMonth=today.get(Calendar.MONTH);
int CDate=today.get(Calendar.DATE);
BDay.set(Calendar.YEAR,today.get(Calendar.YEAR));
// if current month is greater than birth month , then there is no birthday in the current year , means birthday has gone for the year.Hence looking for birthday in the next year by adding 1 to the current year
if (BMonth<CMonth) {
BDay.set(Calendar.YEAR,today.get(Calendar.YEAR)+1);
checkFutureLeapYear=1;
}
// Also if current month and birth month are same , but current date is greater than birth date , then there is no birthday in the current year , means birthday has gone for the year.Hence looking for birthday in the next year by adding 1 to the current year
else if ((BMonth==CMonth)&&(BDate<CDate)) {
BDay.set(Calendar.YEAR,today.get(Calendar.YEAR)+1);
checkFutureLeapYear=1;
}
// code to check that ,is the future year can handle feb 29, same as above conditions
if (checkFutureLeapYear==1) {
CYear=BDay.get(Calendar.YEAR);
Log.v("checkFutureLeapYear",Integer.toString(CYear));
; if (Integer.parseInt(m)==02 && (Integer.parseInt(d)==29)) {
if ((CYear % 4 == 0 && CYear % 100 != 0) || (CYear % 400 == 0)) {
d=d;
}
else {
int date1=Integer.parseInt(d);
date1=(date1-1);
d=Integer.toString(date1);
Log.v("Date 29 subtracted to ",(d));
}
}
startDate=Integer.toString(CYear)+"/"+m+"/"+d;
sdf=new SimpleDateFormat("yyyy/MM/dd");
date=null;
try{
date=sdf.parse(startDate);
}
catch (Exception e) {
e.printStackTrace();
}
BDay.setTime(date);
Log.v("dfdfgdffgfgb",Integer.toString(BDay.get(Calendar.YEAR)));
}
String dayOfTheWeek;
Log.v("Birth year",Integer.toString(BDay.get(Calendar.YEAR)));
Log.v("Birth month",Integer.toString(BDay.get(Calendar.MONTH)));
Log.v("Birth date",Integer.toString(BDay.get(Calendar.DAY_OF_MONTH)));
SimpleDateFormat mFormat = new SimpleDateFormat("EEEE", Locale.US);
dayOfTheWeek = mFormat.format(BDay.getTime());
return dayOfTheWeek;