I need to prepare a list of week day dates
Note :- Week day are not satudrday or sunday, (I can pass the Week day as parameter)
I have written following code but not working, Can you please correct the code
public static void main (String[] args) {
List weekoffDates = new ArrayList<Timestamp>();
Timestamp date = "2013-12-01 00:00:00.0"; //This is timestamp object not string
Timestamp endDate = "2013-12-31 00:00:00.0"; //This is timestamp object not string
int dayOfWeek = 3 //TuesDay
for ( int i =1 ; i<=5; i++ ) {
if( ! date.after(endDate) ) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date.getTime());
calendar.set( Calendar.DAY_OF_WEEK, dayOfWeek ); //This is my parameter
//calendar.set( Calendar.WEEK_OF_MONTH, i );
date = new Timestamp( calendar.getTimeInMillis() );
weekoffDates.add(date);
dayOfWeek = dayOfWeek +7;
System.out.println(date);
}
System.out.println(weekoffDates);
}
}
EDIT:-
date :- 2013:December:1 (I have sent as Timestamp object)
EndDate :- 2013:December:31 (I have sent as Timestamp object)
dayOfWeek :- This is Day Of Week ( I have sent this parameter as tuesday 3 ) //It will change dynamically
Expected Result :-
All tuesday in the month of decemer as ArrayListlist
Problem :- calendar.set( Calendar.DAY_OF_WEEK, dayOfWeek ); setting is wrong