Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar.getInstance

Status
Not open for further replies.

andrewbadera

Programmer
Jan 27, 2002
43
0
0
US
I have a project scheduler I'm building, and I seem to be able to move back and forth between weeks just fine with:

if (actionCmd == "nextWeek") {
cal.set(Calendar.WEEK_OF_YEAR, (cal.get(Calendar.WEEK_OF_YEAR) + 1));
}
if (actionCmd == "prevWeek") {
cal.set(Calendar.WEEK_OF_YEAR, (cal.get(Calendar.WEEK_OF_YEAR) - 1));
}

However, I'm generating a Monday/Friday date for each week using:
Calendar calStart = new GregorianCalendar();
calStart.setTime(rsTimelines.getDate("dateStart"));
//System.out.println("date: " + calStart.get(Calendar.YEAR) + "-" + calStart.get(Calendar.MONTH) + "-" + calStart.get(Calendar.DAY_OF_MONTH) + " DAY_OF_WEEK: " + calStart.get(Calendar.DAY_OF_WEEK));
Calendar calEndProj = new GregorianCalendar();
calEndProj.setTime(rsTimelines.getDate("dateEndProj"));
Calendar calSDate = new GregorianCalendar();
calSDate.setTime(sDate);
Calendar calEDate = new GregorianCalendar();
calEDate.setTime(eDate);

So each time the next/previous button is clicked, the date gets moved up or back a week, and I take a new instance of the calendar to generate my Monday/Friday dates. only it seems that the Monday/Friday dates remain static, the original Monday/Friday of the original week. Is there some sort of re-init or validate or update I need to call on the original Calendar before I getInstance for Mondays and Fridays?
 
sorry missing calendar code:

Calendar calMonday = null;
calMonday = cal.getInstance();
Calendar calFriday = null;
calFriday = cal.getInstance();

java.util.Date sDate;
java.util.Date eDate;

calMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
sDate = calMonday.getTime();

calFriday.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
eDate = calFriday.getTime();
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top