我想计算一年的双周日期。所以我每个月应该有 2 次约会。
到目前为止我已经厌倦了-
private static void getAllBiWeeks() {
int lastYear = java.time.Year.now().getValue() - 1;
int currentYear = java.time.Year.now().getValue();
int nextYear = java.time.Year.now().getValue() + 1;
System.out.println("lastYear - " + lastYear);
System.out.println("currentYear - " + currentYear);
System.out.println("nextYear - " + nextYear);
LocalDate lastYearDate = LocalDate.of(lastYear, 12, 01);
LocalDate currentYearFirstDate = LocalDate.of(currentYear, 01, 01);
LocalDate currentYearLastDate = LocalDate.of(currentYear, 12, 31);
LocalDate nextYearFirstDate = LocalDate.of(nextYear, 01, 01);
System.out.println("lastYearDate - " + lastYearDate);
System.out.println("currentYearFirstDate - " + currentYearFirstDate);
System.out.println("nextYearFirstDate - " + nextYearFirstDate);
LocalDate lastYearLastDate = LocalDate.of(lastYear, 12, 31);
LocalDate lastYearLast15Days = lastYearLastDate.minusWeeks(2);
System.out.println("lastYearLast15Days - " + lastYearLast15Days);
System.out.println(lastYearLast15Days.isBefore(nextYearFirstDate));
for (LocalDate date = currentYearFirstDate; date.isBefore(currentYearLastDate); date = date.plusWeeks(2)) {
System.out.println(date);
}
}
但它没有给出正确的日期,它给出了以下输出 -
lastYear - 2018
currentYear - 2019
nextYear - 2020
lastYearDate - 2018-12-01
currentYearFirstDate - 2019-01-01
nextYearFirstDate - 2020-01-01
lastYearLast15Days - 2018-12-17
true
2019-01-01
2019-01-15
2019-01-29
2019-02-12
2019-02-26
2019-03-12
2019-03-26
2019-04-09
2019-04-23
2019-05-07
2019-05-21
2019-06-04
2019-06-18
2019-07-02
2019-07-16
2019-07-30
2019-08-13
2019-08-27
2019-09-10
2019-09-24
2019-10-08
2019-10-22
2019-11-05
2019-11-19
2019-12-03
2019-12-17
我怎样才能得到这样的日期 -
2019-01-01
2019-01-16
2019-02-01
2019-02-16
.
.
HUWWW
炎炎设计
墨色风雨
相关分类