java - Method to calculate the upcoming birthdays in next N days -


i need method takes integer input (n) , returns birthdays in next n days. finding difficult code running. below code of how want work - in no means working code. highly appreciated.

/* print out birthdays in next n days */ public void show( int n){     calendar cal = calendar.getinstance();     date today = cal.gettime();      // birthdaylist list containing list      // of birthdays format: 12/10/1964 (mm/dd/yyyy)      for(int = 0; i<birthdaylist.getsize(); i++){         if(birthdaylist[i].gettime()- today.gettime()/(1000 * 60 * 60 * 24) == n)){             system.out.println(birthdaylist[i]);         }     }  } 

calendar calendar = calendar.getinstance(locale.english); calendar.settime(new date()); calendar.add(calendar.date, n); // n number of days upto calculated date futuredate = calendar.gettime(); list<string> listofdates = returnlistofdatesbetweentwodates(new date()                                                                 , futuredate); 

where

public static list<string> returnlistofdatesbetweentwodates(java.util.date fromdate,                                                              java.util.date todate) {     list<string> listofdates = lists.newarraylist();     calendar startcal = calendar.getinstance(locale.english);     startcal.settime(fromdate);     calendar endcal = calendar.getinstance(locale.english);     endcal.settime(todate);     while (startcal.gettimeinmillis() <= endcal.gettimeinmillis()){         java.util.date date = startcal.gettime();         listofdates.add(new simpledateformat("dd-mm-yyyy"                                                , locale.english).format(date).trim());         startcal.add(calendar.date, 1);     }     return listofdates; } 

now compare list of dates birthday list of dates , work accordingly


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -