私はこの単純な方法を書いて、すべての支払期日を1月1日の時点で終了しました。私は本当に何が間違っているのかは分かりません。何も返さない。最後の支払期日を見つける
public static List<Date> getPayPeriodDatesSinceStartOfYear() {
Calendar cal = new GregorianCalendar();
cal.add(Calendar.WEEK_OF_YEAR, 1);
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal.set(Calendar.WEEK_OF_YEAR, 2);
Calendar currentDate = new GregorianCalendar();
currentDate.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
int counter = 2;
List<Date> dates = new ArrayList<Date>();
while ((cal.getTime().compareTo((currentDate.getTime())) <= 0)) {
dates.add(cal.getTime());
counter += 2;
cal.set(Calendar.WEEK_OF_YEAR, counter);
}
java.util.Collections.reverse(dates);
if(dates.isEmpty()){
JOptionPane.showMessageDialog(null, "NO DATES, SOMETHING IS WRONG!");
}
return dates;
}
実行時に表示されたメッセージダイアログが表示されますか? – Mitch
ええ、それはポップアップ、私は今年の真ん中に昨年のために働いていると思います。 – davidahines
'getPayPeriodDatesSinceStartOfYear()'名前が示すように、私はあなたが2週間後にそれを実行しなければならないと思います。以来、これは最初の週ですが、今年はまだ支払期間がありません。 –