• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to print last saturday of every month  RSS feed

 
cheguri sridhar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I want to print the last saturday of every month with in given two specified dates, can any one help me on this.

Here is the code that I'm using.

public static List repeatMonthly(int n1,Date startDate,String repeatsEvery,boolean dayofweek)
{
List dates = new ArrayList();
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
if(dayofweek==true)
{
cal.add(Calendar.DAY_OF_WEEK_IN_MONTH,0);
while (n1>=0)
{
n1--;
System.out.println("In If" +cal.getTime());
dates.add(cal.getTime());
cal.add(Calendar.DAY_OF_WEEK_IN_MONTH,cal.getActualMaximum(Calendar.DAY_OF_WEEK_IN_MONTH));
}
}
return dates;
}

Where n1 is the total no of days.

Thanks,
Sridhar
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well does it work? Whats the problem?

Anyway, comments:
1) Please use CODE tags
2) Use meaningful variable names e.g. its better to replace n1 with totalDays rather than using a meaningless name like n1 and having to explain it at the end.
3) There is no need to use == true for a boolean test. The following

should be replaced with

4) What is dayofweek parameter for?
5) Why dont you use two dates for the start and end date?
6) What is repeatsEvery parameter for?
7) What is this line supposed to be doing:

[ November 27, 2008: Message edited by: Tom Johnson ]
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sridhar and welcome to Javaranch!

I see one of the Ranch Hands has already offered some help , in terms of using code tags what he means is this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!