How to generate N number of weeks from the date given - java -


i trying create n of weeks date given , week list should exclude week belongs week.

for example if give todays date generate week excluding week n number of weeks.

below sample serves purpose not able create n number of weeks piece of code prints current week.

calendar currentdate = calendar.getinstance(locale.us); int firstdayofweek = currentdate.getfirstdayofweek();  calendar startdate = calendar.getinstance(locale.us); startdate.settime(currentdate.gettime());  int days = (startdate.get(calendar.day_of_week) + 7 - firstdayofweek) % 7; startdate.add(calendar.date, -days);  calendar enddate = calendar.getinstance(locale.us); enddate.settime(startdate.gettime()); enddate.add(calendar.date, 6);  simpledateformat df = new simpledateformat("yyyy-mm-dd"); system.out.println(df.format(startdate.gettime()) + " - " + df.format(enddate.gettime()));  

could 1 me on this?

print n number of weeks given date [excludes current week]:

public static void printnweeks(calendar startdate, int weeks) {      int firstdayofweek = startdate.getfirstdayofweek();     int days = (startdate.get(calendar.day_of_week) + 7 - firstdayofweek) % 7;     startdate.add(calendar.date, -days);      simpledateformat df = new simpledateformat("yyyy-mm-dd");      (int = 1; <= weeks; i++) {          startdate.add(calendar.date, 7); // change 7 -7 dates          calendar enddate = calendar.getinstance(locale.us);         enddate.settime(startdate.gettime());         enddate.add(calendar.date, 6);                    system.out.println(df.format(startdate.gettime()) + " - "                 + df.format(enddate.gettime()));     } } 

sample invocations:

public static void main(string[] args) {             //from given date     calendar startdate = calendar.getinstance(locale.us);     startdate.set(2015, calendar.january, 30);     printnweeks(startdate, 5);      //from current date          startdate = calendar.getinstance(locale.us);     printnweeks(startdate, 5); } 

Comments