Here you can find the source of addWeekdays(Calendar cal, int days)
private static void addWeekdays(Calendar cal, int days)
//package com.java2s; /******************************************************************************* * Copyright 2011 Matt Burns//from www .j av a 2s.c om * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.util.Calendar; public class Main { private static void addWeekdays(Calendar cal, int days) { // This looks crazy to me but I can't seem to describe the same // functionality in a clear way... while (days > 0) { while (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.add(Calendar.DATE, 1); } cal.add(Calendar.DATE, 1); days--; while (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.add(Calendar.DATE, 1); } } } }