I want to add certain number of hours to date, ignoring the weekends
For example,
(Friday 18:00) + 48 = (Tuseday 18:00) (Saturday and Sunday are ignored)
you need to handle it in custom way:
public Date getTaskEndTime(Calendar startDate, int hours) {
Calendar endTime = Calendar.getInstance();
endTime.setTime(startDate.getTime());
endTime.add(Calendar.HOUR, hours); // add 2 for saturday and sunday
int dayOfWeek = endTime.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == Calendar.SATURDAY) {
endTime.add(Calendar.DATE, 2); // add 2 for saturday and sunday
} else if (dayOfWeek == Calendar.SATURDAY) {
endTime.add(Calendar.DATE, 1); // add 1 for sunday
}
return endTime.getTime();
}