Here you can find the source of addWorkdays(Date date, int workdayOffset)
Parameter | Description |
---|---|
date | Nie <code>null</code> |
workdayOffset | Offset in Tagen (1=morgen) |
null
(Tagesdatum ohne
public static Date addWorkdays(Date date, int workdayOffset)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.util.Calendar; import java.util.Date; public class Main { /**/*from w ww . j av a2 s .c om*/ * Die Anzahl Arbeitstage (d.h. nicht Samstag und Sonntag) addieren. * * @param date Nie <code>null</code> * @param workdayOffset Offset in Tagen (1=morgen) * @return Nie <code>null</code> (Tagesdatum ohne */ public static Date addWorkdays(Date date, int workdayOffset) { final Calendar cal = getCalendarInstance(); cal.setTime(date); ensureWorkday(cal); for (int countdown = workdayOffset; countdown > 0; countdown--) { cal.add(Calendar.DAY_OF_YEAR, 1); ensureWorkday(cal); } final Date result = cal.getTime(); return result; } /** * Locale? * * @return Eine neue Instanz. */ private static Calendar getCalendarInstance() { final Calendar cal = Calendar.getInstance(); return cal; } /** * Ensure workday. * * @param cal the cal */ protected static void ensureWorkday(Calendar cal) { int dow = cal.get(Calendar.DAY_OF_WEEK); while (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) { cal.add(Calendar.DAY_OF_YEAR, 1); dow = cal.get(Calendar.DAY_OF_WEEK); } } }