私はJavaが初めてで、土曜日と日曜日を除く稼働日数を取得する次のコードを見つけました。
この関数を呼び出して現在の月main()
を表示する方法を知る必要があります。workDays
ありがとう。
package mypkg;
import java.sql.Date;
import java.util.Calendar;
public class workrays {
public static int getWorkingDaysBetweenTwoDates(Date startDate, Date endDate) {
Calendar startCal;
Calendar endCal;
startCal = Calendar.getInstance();
startCal.setTime(startDate);
endCal = Calendar.getInstance();
endCal.setTime(endDate);
int workDays = 0;
//Return 0 if start and end are the same
if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {
return 0;
}
if (startCal.getTimeInMillis() > endCal.getTimeInMillis()) {
startCal.setTime(endDate);
endCal.setTime(startDate);
}
do {
startCal.add(Calendar.DAY_OF_MONTH, 1);
if (startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
&& startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
++workDays;
}
} while (startCal.getTimeInMillis() < endCal.getTimeInMillis());
return workDays;
}
public static void main(String args[]) {
getWorkingDaysBetweenTwoDates(Date startDate, Date endDate);
System.out.println(workdays);
}
}