I'm need to do a method that returns the position of actual day in the next month.
for today (20/12/2016)
I need to call this method whit today date
The return given must to be (17/01/2016)
This method must return the third Tuesday of the next month
Is the 4 week of this month, but I need the Third Tuesday.
I try to use Calendar.MONTH, Calendar.WEEK_OF_MONTH, Calendar.DAY_OF_WEEK but I can't get the third, I always get the fourth.
Some thing like this:
public static Date getNextMonthDayOfWeel(Date d) {
Calendar c = Calendar.getInstance();
c.setTime(d);
int week = c.get(Calendar.WEEK_OF_MONTH);
int day = c.get(Calendar.DAY_OF_WEEK);
//// this block
if(!firstWeekOfMonthHad(day)){
week++;
}
//// this block
c.setFirstDayOfWeek(Calendar.SUNDAY);
c.add(Calendar.MONTH, 1);
c.set(Calendar.WEEK_OF_MONTH, week);
c.set(Calendar.DAY_OF_WEEK, day);
return c.getTime();
}
How can I get if the first week of the month have the specific day of the week?
If you use Java 8 or later, it is as simple as: