我决定从5.5升级到Optaplanner 7.5 Nurseroster,但遇到了许多愚蠢的问题。下面是一个。我以前使用的例程如下。现在,新版本需要LocalDate。我有一个MySql数据库后端,用户通过日历选择花名册计划计划器。任何建议将不胜感激。
int shiftDateSize = maxDayIndex + 1;
List<ShiftDate> shiftDateList = new ArrayList<ShiftDate>(shiftDateSize);
//shiftDateMap = new HashMap<String, ShiftDate>(shiftDateSize);
long id = 0L;
int dayIndex = 0;
calendar.setTime(startDate);
for (int i = 0; i < shiftDateSize; i++) {
ShiftDate shiftDate = new ShiftDate();
shiftDate.setId(id);
shiftDate.setDayIndex(dayIndex);
**String dateString = dateFormat.format(calendar.getTime());**
shiftDate.setDateString(dateString);
**shiftDate.setDayOfWeek(DayOfWeek.valueOfCalendar(calendar.get(Calendar.DAY_OF_WEEK)));**
shiftDate.setShiftList(new ArrayList<Shift>());
shiftDateList.add(shiftDate);
shiftDateMap.put(dateString, shiftDate);
id++;
dayIndex++;
calendar.add(Calendar.DAY_OF_YEAR, 1);
}
nurseRoster.setShiftDateList(shiftDateList);
}
请您参考如下方法:
我已经尝试使用以下代码从日历中获取 LocalDate
Calendar calendar = Calendar.getInstance();
TimeZone tz = calendar.getTimeZone();
ZoneId zid = tz == null ? ZoneId.systemDefault() : tz.toZoneId();
LocalDate localDate = LocalDateTime.ofInstant(calendar.toInstant(), zid).LocalDate();
或简单地一行:
LocalDate localDate = LocalDateTime.ofInstant(calendar.toInstant(), calendar.getTimeZone().toZoneId()).toLocalDate();
我从此链接 Convert Calendar to LocalDateTime遵循了这些步骤