datetime - processing last 10 working(business) days java -
i tried write code displays day of week lastly 10 dates.
here's part of code:
calendar cal = calendar.getinstance(); for(int i=0; i<=9;i++) { cal.add(calendar.date, -i); date tday=cal.gettime(); simpledateformat dy = new simpledateformat("eee"); string d9 = dy.format(tday); system.out.println(d9); } instead of showing lastly 10 days in order displaying:
thu wed mon fri mon wed thu thu wed mon fri
where did made mistake? please help me?
try this.
boolean work = true; int day = 0; // 0 = today, 1 = yesterday etc... int subday = 0; // subtract day while (work){ calendar cal = calendar.getinstance(); // current time cal.add(calendar.day_of_week, subday); // subtract day // working days mon, tue, wed, thu, fri. if saturdays or sundays, want skip days, // utilize if declaration if (cal.get(calendar.day_of_week) == calendar.saturday || cal.get(calendar.day_of_week) == calendar.sunday) { subday--; continue; } date tday=cal.gettime(); simpledateformat dy = new simpledateformat("eee"); string d9 = dy.format(tday); system.out.println("day: " + day + " - " + d9); day ++; subday--; if (day >= 10){work=false;} // here declara how much day want go back, , break loop. } java datetime calendar
No comments:
Post a Comment