我正在尝试使用过期日期表中的 LocalDate 来比较两个日期。问题是我无法根据 dateExpiry 正确设置行格式这应该是这样的:
if(today.isEqual(LocalDate.parse(medicament))){
currentRow.setStyle("-fx-background-color:tomato");
} else if (today.before(LocalDate.parse(medicament).plusMonths(3))) {
currentRow.setStyle("-fx-background-color:orange");
} else {
currentRow.setStyle("-fx-background-color:lightgreen");
}
如何正确设置单元格格式
导入java.time.LocalDate;
public class ExpireDateTable {
public static void main(String[] args) {
// Sample dates
LocalDate currentDate
= LocalDate.now(); 本地日期日期到期 = LocalDate.of(2024, 2, 28); // 例子 有效期
// Comparing dates and applying row formatting
if (dateExpiry.isBefore(currentDate)) {
System.out.println("Row formatting: Date expired, apply formatting for past expiry date.");
// Apply formatting for past expiry date
} else if (dateExpiry.isEqual(currentDate)) {
System.out.println("Row formatting: Date expiring today, apply formatting accordingly.");
// Apply formatting for expiry date today
} else {
System.out.println("Row formatting: Date is in the future, no special formatting needed.");
// Apply default formatting
}
}
}